Bug 2576594 - python-asyncpg fails to build with Python 3.16: ValueError: Port could not be cast to integer value as '1111,host2:2222'
Summary: python-asyncpg fails to build with Python 3.16: ValueError: Port could not be...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python-asyncpg
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Ben Beasley
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.16
TreeView+ depends on / blocked
 
Reported: 2026-11-19 13:07 UTC by Karolina Surma
Modified: 2026-11-20 13:11 UTC (History)
3 users (show)

Fixed In Version: python-asyncpg-0.32.0-4.fc46
Clone Of:
Environment:
Last Closed: 2026-11-20 07:05:55 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github MagicStack asyncpg issues 1409 0 None open Python 3.16.0a2: TestConnectParams.test_connect_params fails 2026-11-20 06:16:09 UTC
Github python cpython issues 161987 0 None closed urllib.parse: port validation at parse time (gh-88037) breaks multi-host URLs; backported to 3.14 and 3.15 2026-11-20 06:27:38 UTC
Github python cpython issues 88037 0 None closed urllib.parse.urlparse doesn't check port 2026-11-20 06:27:38 UTC

Description Karolina Surma 2026-11-19 13:07:28 UTC
python-asyncpg fails to build with Python 3.16.0a2.

_ 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 "/builddir/build/BUILD/python-asyncpg-0.32.0-build/python-asyncpg-0.32.0/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 "/builddir/build/BUILD/python-asyncpg-0.32.0-build/BUILDROOT/usr/lib64/python3.16/site-packages/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 "/builddir/build/BUILD/python-asyncpg-0.32.0-build/python-asyncpg-0.32.0/tests/test_connect.py", line 1268, in test_connect_params
    self.run_testcase(testcase)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/builddir/build/BUILD/python-asyncpg-0.32.0-build/python-asyncpg-0.32.0/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

https://docs.python.org/3.16/whatsnew/3.16.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.16/fedora-rawhide-x86_64/11359624-python-asyncpg/

For all our attempts to build python-asyncpg with Python 3.16, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.16/package/python-asyncpg/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.16:
https://copr.fedorainfracloud.org/coprs/g/python/python3.16/

Let us know here if you have any questions.

Python 3.16 is planned to be included in Fedora 47.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.16.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Ben Beasley 2026-11-20 06:16:10 UTC
This is new in Python 3.16.0a2. There seems to have been some kind of a change in URL parsing, but I couldn’t find anything obviously relevant in https://docs.python.org/3.16/whatsnew/changelog.html#python-3-16-0-alpha-2. For now, I’ve reported it upstream in https://github.com/MagicStack/asyncpg/issues/1409 and will skip the test.

Comment 2 Ben Beasley 2026-11-20 06:27:39 UTC
I understand this one now. See https://github.com/MagicStack/asyncpg/issues/1409#issuecomment-7032249761.

> This is due to https://github.com/python/cpython/pull/159122, for https://github.com/python/cpython/issues/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, https://github.com/python/cpython/issues/161987. It looks like this change will stay in Python 3.16, so `asyncpg` will have to figure out how to deal with it.

I’m still skipping the test rather than attempting a fix.

Comment 3 Fedora Update System 2026-11-20 07:03:05 UTC
FEDORA-2026-214cdc187d (python-asyncpg-0.32.0-4.fc46) has been submitted as an update to Fedora 46.
https://bodhi.fedoraproject.org/updates/FEDORA-2026-214cdc187d

Comment 4 Fedora Update System 2026-11-20 07:05:55 UTC
FEDORA-2026-214cdc187d (python-asyncpg-0.32.0-4.fc46) has been pushed to the Fedora 46 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 5 Karolina Surma 2026-11-20 13:11:57 UTC
(In reply to Ben Beasley from comment #2)
> I understand this one now. See
> https://github.com/MagicStack/asyncpg/issues/1409#issuecomment-7032249761.
> 
> > This is due to https://github.com/python/cpython/pull/159122, for https://github.com/python/cpython/issues/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, https://github.com/python/cpython/issues/161987. It looks like this change will stay in Python 3.16, so `asyncpg` will have to figure out how to deal with it.
> 
> I’m still skipping the test rather than attempting a fix.

Thank you for taking care of it.

Yes, I think the change is intentional for Python 3.16, as in https://docs.python.org/3.16/whatsnew/3.16.html#porting-to-python-3-16 (second bullet point):

urllib.parse.urlsplit() and urllib.parse.urlparse() now raise ValueError when the URL is parsed if the port is not a decimal number or is outside the range 0–65535. Previously, the error was only raised when the port attribute was read. This also affects urljoin(), and urldefrag() for URLs with a fragment. Code which never read port may now fail on URLs such as:
    SCP-style addresses given a scheme, such as git+ssh://git:org/repo.git;
    multi-host URLs with ports, such as mongodb://h1:27017,h2:27017/db or postgresql://h1:5432,h2:5433/db;
    URL templates with a placeholder port, such as http://localhost:{port}/.

These are not valid URLs under RFC 3986. To process them, split off the netloc yourself before calling urlsplit(), for example by replacing it with a placeholder host, or fill in templates before parsing them. (Contributed by Miguel Brito and Senthil Kumaran in gh-88037.)


Note You need to log in before you can comment on or make changes to this bug.