You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ git clone https://github.com/MagicStack/asyncpg.git
$ cd asyncpg
$ uv venv --python 3.16
Using CPython 3.16.0a2 interpreter at: /usr/bin/python3.16
[…]
$ . .venv/bin/activate
(asyncpg) $ uv pip install -e .[gssauth]
(asyncpg) $ uv pip install --group test
(asyncpg) $ PYTHONASYNCIODEBUG=1 pytest -v
[…]
================================== short test summary info ==================================
SUBFAILED(dsn='postgresql://user@host1:1111,host2:2222/db', env={}) tests/test_connect.py::TestConnectParams::test_connect_params - ValueError: Port could not be cast to integer value as '1111,host2:2222'
FAILED tests/test_connect.py::TestConnectParams::test_connect_params - UnboundLocalError: cannot access local variable 'params' where it is not associated with...
FAILED tests/test_connect.py::TestConnectionAttributes::test_prefer_standby_picks_master_when_standby_is_down - TimeoutError
=== 3 failed, 376 passed, 5 skipped, 5 warnings, 702 subtests passed in 143.55s (0:02:23) ===
These seem to be new with Python 3.16.0a2 (since 3.16.0a1).
The TestConnectParams::test_connect_params regression was detected downstream in Fedora, where we are already testing Python 3.16. The timeout in TestConnectionAttributes::test_prefer_standby_picks_master_when_standby_is_down regression only appears when working in a git checkout, not in the downstream RPM package build.
========================================= FAILURES ==========================================
_ TestConnectParams.test_connect_params (dsn='postgresql://user@host1:1111,host2:2222/db', env={}) _
Traceback (most recent call last):
File "/usr/lib64/python3.16/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib64/python3.16/unittest/case.py", line 587, in subTest
yield
File "/home/ben/src/forks/asyncpg/tests/test_connect.py", line 1184, in run_testcase
addrs, params = connect_utils._parse_connect_dsn_and_args(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
dsn=dsn, host=host, port=port, user=user, password=password,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
krbsrvname=krbsrvname, gsslib=gsslib,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
service=service, servicefile=servicefile)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ben/src/forks/asyncpg/asyncpg/connect_utils.py", line 295, in _parse_connect_dsn_and_args
parsed = urllib.parse.urlparse(dsn)
File "/usr/lib64/python3.16/urllib/parse.py", line 486, in urlparse
scheme, netloc, url, params, query, fragment = _urlparse(url, scheme, allow_fragments)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.16/urllib/parse.py", line 499, in _urlparse
scheme, netloc, url, query, fragment = _urlsplit(url, scheme, allow_fragments)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.16/urllib/parse.py", line 646, in _urlsplit
_checknetloc(netloc)
~~~~~~~~~~~~^^^^^^^^
File "/usr/lib64/python3.16/urllib/parse.py", line 547, in _checknetloc
_validate_port(port)
~~~~~~~~~~~~~~^^^^^^
File "/usr/lib64/python3.16/urllib/parse.py", line 166, in _validate_port
raise ValueError(f"Port could not be cast to integer value as {port!r}")
ValueError: Port could not be cast to integer value as '1111,host2:2222'
___________________________ TestConnectParams.test_connect_params ___________________________
Traceback (most recent call last):
File "/usr/lib64/python3.16/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib64/python3.16/unittest/case.py", line 691, in run
self._callTestMethod(testMethod)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/usr/lib64/python3.16/unittest/case.py", line 637, in _callTestMethod
result = method()
File "/home/ben/src/forks/asyncpg/tests/test_connect.py", line 1268, in test_connect_params
self.run_testcase(testcase)
~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/home/ben/src/forks/asyncpg/tests/test_connect.py", line 1207, in run_testcase
params.pop('ssl', None)
^^^^^^
UnboundLocalError: cannot access local variable 'params' where it is not associated with a value
______ TestConnectionAttributes.test_prefer_standby_picks_master_when_standby_is_down _______
Traceback (most recent call last):
File "/home/ben/src/forks/asyncpg/asyncpg/connection.py", line 2498, in connect
return await connect_utils._connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<22 lines>...
)
^
File "/home/ben/src/forks/asyncpg/asyncpg/connect_utils.py", line 1278, in _connect
conn = await _connect_addr(
^^^^^^^^^^^^^^^^^^^^
...<6 lines>...
)
^
File "/home/ben/src/forks/asyncpg/asyncpg/connect_utils.py", line 1092, in _connect_addr
return await __connect_addr(params, True, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ben/src/forks/asyncpg/asyncpg/connect_utils.py", line 1162, in __connect_addr
tr, pr = await connector
^^^^^^^^^^^^^^^
File "/home/ben/src/forks/asyncpg/asyncpg/connect_utils.py", line 996, in _create_ssl_connection
tr, pr = await loop.create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
host, port)
^^^^^^^^^^^
File "/usr/lib64/python3.16/asyncio/base_events.py", line 1154, in create_connection
sock = await self._connect_sock(
^^^^^^^^^^^^^^^^^^^^^^^^^
exceptions, addrinfo, laddr_infos)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.16/asyncio/base_events.py", line 1053, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/lib64/python3.16/asyncio/selector_events.py", line 653, in sock_connect
return await fut
^^^^^^^^^
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib64/python3.16/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib64/python3.16/unittest/case.py", line 691, in run
self._callTestMethod(testMethod)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/usr/lib64/python3.16/unittest/case.py", line 637, in _callTestMethod
result = method()
File "/home/ben/src/forks/asyncpg/asyncpg/_testbase/__init__.py", line 92, in wrapper
self.loop.run_until_complete(coro)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/usr/lib64/python3.16/asyncio/base_events.py", line 730, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "/home/ben/src/forks/asyncpg/tests/test_connect.py", line 2991, in test_prefer_standby_picks_master_when_standby_is_down
con = await self.connect(**connection_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ben/src/forks/asyncpg/asyncpg/connection.py", line 2497, in connect
async with compat.timeout(timeout):
~~~~~~~~~~~~~~^^^^^^^^^
File "/usr/lib64/python3.16/asyncio/timeouts.py", line 115, in __aexit__
raise TimeoutError from exc_val
TimeoutError
This is due to python/cpython#159122, for python/cpython#88037. I suppose that asyncpg was previously relying on the fact that the port being parsed as 1111,host2:2222 only produced an error if the port attribute of the parsed URL object was actually accessed.
The change was backported to Python 3.14 and 3.15, but then was reverted once it was discovered that it breaks multi-host URLs like the one in this test, python/cpython#161987. It looks like this change will stay in Python 3.16, so asyncpg will have to figure out how to deal with it.
Activity
musicinmybrain commentedon Nov 20, 2026
musicinmybrain commentedon Nov 20, 2026
musicinmybrain commentedon Nov 20, 2026
Hmm, I think I have figured this out.
This is due to python/cpython#159122, for python/cpython#88037. I suppose that
asyncpgwas previously relying on the fact that the port being parsed as1111,host2:2222only produced an error if theportattribute of the parsed URL object was actually accessed.The change was backported to Python 3.14 and 3.15, but then was reverted once it was discovered that it breaks multi-host URLs like the one in this test, python/cpython#161987. It looks like this change will stay in Python 3.16, so
asyncpgwill have to figure out how to deal with it.