Opened 13 months ago

Closed 12 days ago

Last modified 7 days ago

#35844 closed New feature (fixed)

Python 3.14 compatibility.

Reported by: Mariusz Felisiak Owned by: Mariusz Felisiak
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Michał Górny Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Python 3.14 final is scheduled for October 2025 (see ​PEP 745). This is a tracking ticket for compatibility fixes for Django submitted in the meantime.

Django 5.2 will be the first version to support Python 3.14, because Django 5.1 will end the mainstream support in April 2024.

Change History (30)

comment:1 by Claude Paroz, 13 months ago

Triage Stage: UnreviewedAccepted
Version: 5.0dev

comment:2 by Mariusz Felisiak, 13 months ago

Initial PRs:

After applying these 3 changes we'll have one more deprecation warning, 49 test failures, and 24 test errors. All of them are under investigation of Team Venus of the 3rd Djangonauts cohort, PRs will be submitted soonish :)

comment:3 by GitHub <noreply@…>, 13 months ago

In 48fa531:

Refs #35844 -- Added Python 3.14 to daily builds.

comment:4 by GitHub <noreply@…>, 13 months ago

In bd3b1dfa:

Refs #35844 -- Used asgiref.sync.iscoroutinefunction() instead of deprecated asyncio.iscoroutinefunction().

Fixes DeprecationWarning:

'asyncio.iscoroutinefunction' is deprecated and slated for removal in
Python 3.16; use inspect.iscoroutinefunction() instead.

comment:5 by GitHub <noreply@…>, 12 months ago

In 34066d6:

Refs #35844 -- Fixed tests for test --parallel option on Python 3.14+.

"forkserver" is the new default on POSIX systems, and Django doesn't
support parallel tests with "forkserver":

https://github.com/python/cpython/commit/b65f2cdfa77d8d12c213aec663ddaaa30d75a4b2

comment:6 by Sarah Boyce <42296566+sarahboyce@…>, 12 months ago

In 4c3897b:

Refs #35844 -- Corrected expected error messages in commands tests on Python 3.14+.

Updated CommandTests.test_subparser_invalid_option and CommandDBOptionChoiceTests.test_invalid_choice_db_option to address changes in Python 3.14+ error handling.

comment:7 by Mariusz Felisiak, 12 months ago

FYI: urljoin() behavior change has been accepted as a regression in Python 3.14, https://github.com/python/cpython/issues/125926.

comment:8 by Claude Paroz <claude@…>, 12 months ago

In fc22fdd3:

Refs #35844 -- Expanded compatibility for expected error messages in command tests on Python 3.12 and 3.13.

Updated CommandTests.test_subparser_invalid_option and CommandDBOptionChoiceTests.test_invalid_choice_db_option to use assertRaisesRegex() for compatibility with modified error messages in Python 3.12, 3.13, and 3.14+..

comment:9 by Sarah Boyce <42296566+sarahboyce@…>, 12 months ago

In b57a839:

[5.1.x] Refs #35844 -- Expanded compatibility for expected error messages in command tests on Python 3.12 and 3.13.

Updated CommandTests.test_subparser_invalid_option and CommandDBOptionChoiceTests.test_invalid_choice_db_option to use assertRaisesRegex() for compatibility with modified error messages in Python 3.12, 3.13, and 3.14+..

Backport of fc22fdd34f1e55adde161f5f2dca8db90bbfce80 from main.

comment:10 by Sarah Boyce <42296566+sarahboyce@…>, 12 months ago

In 5064ddb:

[5.0.x] Refs #35844 -- Expanded compatibility for expected error messages in command tests on Python 3.12.

Updated CommandTests.test_subparser_invalid_option and CommandDBOptionChoiceTests.test_invalid_choice_db_option to use assertRaisesRegex() for compatibility with modified error messages in Python 3.12, 3.13, and 3.14+..

Backport of fc22fdd34f1e55adde161f5f2dca8db90bbfce80 from main.

comment:11 by Sarah Boyce <42296566+sarahboyce@…>, 12 months ago

In ea4a1fb:

[4.2.x] Refs #35844 -- Expanded compatibility for expected error messages in command tests on Python 3.12.

Updated CommandTests.test_subparser_invalid_option and CommandDBOptionChoiceTests.test_invalid_choice_db_option to use assertRaisesRegex() for compatibility with modified error messages in Python 3.12, 3.13, and 3.14+..

Backport of fc22fdd34f1e55adde161f5f2dca8db90bbfce80 from main.

in reply to:  7 comment:12 by Mariusz Felisiak, 12 months ago

Replying to Mariusz Felisiak:

FYI: urljoin() behavior change has been accepted as a regression in Python 3.14, https://github.com/python/cpython/issues/125926.

Fixed in https://github.com/python/cpython/commit/dbb6e22cb1f533bba00a61a5b63ec68af9d48836.

comment:13 by Sarah Boyce <42296566+sarahboyce@…>, 11 months ago

In 8d7b142:

Refs #35844 -- Fixed copying BaseContext and its subclasses on Python 3.14+.

super objects are copyable on Python 3.14+:

https://github.com/python/cpython/commit/5ca4e34bc1aab8321911aac6d5b2b9e75ff764d8

and can no longer be used in BaseContext.copy().

comment:14 by Sarah Boyce <42296566+sarahboyce@…>, 10 months ago

In fcd9d08:

Refs #35844 -- Fixed OtherModelFormTests.test_prefetch_related_queryset() test on Python 3.14+.

https://github.com/python/cpython/commit/5a23994a3dbee43a0b08f5920032f60f38b63071

comment:15 by GitHub <noreply@…>, 10 months ago

In 0a341125:

Refs #35844 -- Removed unnecessary ArgumentParser.add_argument_group()'s prefix_chars argument.

The prefix_chars argument is deprecated since https://github.com/python/cpython/commit/7b04496e5c7ed47e9653f4591674fc9ffef34587.

comment:16 by GitHub <noreply@…>, 6 months ago

In d6925f0:

Refs #35844 -- Skipped argon2-cffi requirement in Windows for Python 3.14+.

comment:17 by GitHub <noreply@…>, 6 months ago

In 0b2ed4f7:

Refs #35844 -- Skipped selenium and geoip2 requirement in Windows for Python 3.14+.

Follow up to d6925f0d6beb3c08ae24bdb8fd83ddb13d1756e4.

comment:18 by GitHub <noreply@…>, 4 months ago

In 426be740:

Refs #35844, #35945 -- Used asgiref.sync.iscoroutinefunction() instead of deprecated asyncio.iscoroutinefunction().

Follow up to bd3b1dfa2422e02ced3a894adb7544e42540c97d.
Introduced in 2ae3044d9d4dfb8371055513e440e0384f211963.

Fixes DeprecationWarning:

'asyncio.iscoroutinefunction' is deprecated and slated for removal
in Python 3.16; use inspect.iscoroutinefunction() instead.

comment:19 by Michał Górny, 3 months ago

Cc: Michał Górny added

comment:20 by GitHub <noreply@…>, 3 months ago

In 500bd42:

Refs #35844 -- Readded optional requirements on daily builds for Python 3.14.

comment:21 by Mariusz Felisiak, 12 days ago

Has patch: set

comment:22 by Jacob Walls, 12 days ago

Triage Stage: AcceptedReady for checkin

comment:23 by Mariusz Felisiak <felisiak.mariusz@…>, 12 days ago

In 2d9c194:

Refs #35844 -- Relaxed GEOSIOTest.test02_wktwriter() test assertion.

comment:24 by Mariusz Felisiak <felisiak.mariusz@…>, 12 days ago

In 56977b46:

Refs #35844 -- Doc'd Python 3.14 compatibility.

comment:25 by Mariusz Felisiak <felisiak.mariusz@…>, 12 days ago

In 915d10a:

[6.0.x] Refs #35844 -- Relaxed GEOSIOTest.test02_wktwriter() test assertion.

Backport of 2d9c194d5a0d9ae746e16ee5f641e30d544dc31b from main

comment:26 by Mariusz Felisiak <felisiak.mariusz@…>, 12 days ago

In a27c2ef:

[6.0.x] Refs #35844 -- Doc'd Python 3.14 compatibility.

Backport of 56977b466c33ca3da14a1ed2609172425a76a34e from main.

comment:27 by Mariusz Felisiak <felisiak.mariusz@…>, 12 days ago

In a8c9b5b:

[5.2.x] Refs #35844 -- Doc'd Python 3.14 compatibility.

Backport of 56977b466c33ca3da14a1ed2609172425a76a34e from main.

comment:28 by Mariusz Felisiak, 12 days ago

Resolution: fixed
Status: assignedclosed

comment:29 by Natalia Bidart, 7 days ago

GHA are showing this error on test runs on linux, which I also get locally:

======================================================================
FAIL: test_custom_project_template_context_variables (admin_scripts.tests.StartProject.test_custom_project_template_context_variables)
Make sure template context variables are rendered with proper values
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/unittest/case.py", line 669, in run
    self._callTestMethod(testMethod)
    
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/unittest/case.py", line 615, in _callTestMethod
    result = method()
    ^^^^^^^^^^^^^^^
  File "/home/runner/work/django/django/tests/admin_scripts/tests.py", line 2859, in test_custom_project_template_context_variables
    self.assertIn('project_directory = "%s"' % testproject_dir, content)
    ^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/unittest/case.py", line 1192, in assertIn
    self.fail(self._formatMessage(msg, standardMsg))
    ^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/unittest/case.py", line 750, in fail
    raise self.failureException(msg)
    ^^^^^^^^^^^^^^^
AssertionError: 'project_directory = "/tmp/django_znh73pf9/django_hl40h621/tmp44uj0vns/test_project/project_dir"' not found in '# The manage.py of the another_project test project\n\n# template context:\nproject_name = "another_project"\nproject_directory = (\n    "/tmp/django_znh73pf9/django_hl40h621/tmp44uj0vns/test_project/project_dir"\n)\nsecret_key = "django-insecure-j8z2ob$oh3de^_2&lv=z9b+=h*pnh_c#y3##je+%jy&a6+prr1"\n'

I'll work on a fix.

comment:30 by Natalia Bidart, 7 days ago

Created #36680 to track the test failure. This is about temp dirs having longer names (likely related to Python 3.14 and forkserver) and having black installed in the venv.

Note: See TracTickets for help on using tickets.
Back to Top