Opened 2 years ago

Closed 13 months ago

Last modified 5 months ago

#34118 closed New feature (fixed)

Python 3.12 compatibility

Reported by: Mariusz Felisiak Owned by: Mariusz Felisiak
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: bcail, David Sanders, Sam James Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Python 3.12 final is scheduled for October 2023 (see PEP 693). This is a tracking ticket for compatibility fixes for Django submitted in the meantime.

Django 4.2 will be the first version to support Python 3.12, because Django 4.1 will end the mainstream support in April 2023.

Change History (42)

comment:1 by bcail, 2 years ago

Cc: bcail added

comment:2 by David Sanders, 2 years ago

Cc: David Sanders added

comment:3 by David Sanders, 2 years ago

I'm getting errors on the following which was working for 3.11.0.

I'm on macos 12.6

tests main % python --version
Python 3.11.0
tests main % ./runtests.py queries.tests.Queries1Tests.test_avoid_infinite_loop_on_too_many_subqueries
Testing against Django installed in '/Users/dsanders/projects/django/django' with up to 10 processes
Found 1 test(s).
Creating test database for alias 'default'...
System check identified no issues (1 silenced).
.
----------------------------------------------------------------------
Ran 1 test in 0.295s

OK
Destroying test database for alias 'default'...


… 8< … switch venvs


tests main % python --version
Python 3.12.0a1
tests main % ./runtests.py queries.tests.Queries1Tests.test_avoid_infinite_loop_on_too_many_subqueries
Testing against Django installed in '/Users/dsanders/projects/django/django' with up to 10 processes
Found 1 test(s).
Creating test database for alias 'default'...
System check identified no issues (1 silenced).
F
======================================================================
FAIL: test_avoid_infinite_loop_on_too_many_subqueries (queries.tests.Queries1Tests.test_avoid_infinite_loop_on_too_many_subqueries)
----------------------------------------------------------------------
RecursionError: maximum recursion depth exceeded

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/dsanders/projects/django/tests/queries/tests.py", line 550, in test_avoid_infinite_loop_on_too_many_subqueries
    with self.assertRaisesMessage(RecursionError, msg):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 155, in __exit__
    self.gen.throw(value)
  File "/Users/dsanders/projects/django/django/test/testcases.py", line 890, in _assert_raises_or_warns_cm
    self.assertIn(expected_message, str(getattr(cm, cm_attr)))
AssertionError: 'Maximum recursion depth exceeded: too many subqueries.' not found in 'maximum recursion depth exceeded'

----------------------------------------------------------------------
Ran 1 test in 0.207s

FAILED (failures=1)
Destroying test database for alias 'default'...
Last edited 2 years ago by David Sanders (previous) (diff)

comment:4 by bcail, 2 years ago

Another data point: SQLite and Postgres tests pass for me on Linux with Python 3.12 alpha 1.

comment:5 by GitHub <noreply@…>, 2 years ago

In 67504ea5:

Refs #34118 -- Skipped not compatible requirements on daily builds for Python 3.12.

comment:6 by GitHub <noreply@…>, 2 years ago

In 2848e5d:

Refs #34118 -- Used smtplib's context parameter instead of keyfile and certfile.

keyfile and certfile parameters were removed in Python 3.12, see
https://github.com/python/cpython/commit/ef0e72b31d22f780d3a165d7d0471806061fe380

comment:7 by GitHub <noreply@…>, 2 years ago

In 32d70b2:

Refs #34118 -- Adopted asgiref coroutine detection shims.

Thanks to Mariusz Felisiak for review.

comment:8 by GitHub <noreply@…>, 2 years ago

In 829f4d1:

Refs #31546, Refs #34118 -- Corrected CommandTests.test_requires_system_checks_specific().

System checks are never called without skip_checks=False. Moreover,
called_once_with() is not a proper assertion and raise AttributeError
on Python 3.12.

comment:9 by GitHub <noreply@…>, 21 months ago

In 38e63c9:

Refs #34118 -- Fixed CustomChoicesTests.test_uuid_unsupported on Python 3.12+.

https://github.com/python/cpython/commit/2a4d8c0a9e88f45047da640ce5a92b304d2d39b1

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 21 months ago

In 32cfa73c:

[4.2.x] Refs #34118 -- Fixed CustomChoicesTests.test_uuid_unsupported on Python 3.12+.

https://github.com/python/cpython/commit/2a4d8c0a9e88f45047da640ce5a92b304d2d39b1
Backport of 38e63c9e61152682f3ff982c85a73793ab6d3267 from main

comment:11 by Sam James, 21 months ago

Hi folks,

https://github.com/django/django/commit/38e63c9e61152682f3ff982c85a73793ab6d3267 was applied to fix Python 3.12, but cpython upstream have backported the fix for https://github.com/python/cpython/issues/102549 to Python 3.11 too.

The Django patch will need adjusting to probably just allow both output messages (or sniff the Python minor/patch version).

Last edited 21 months ago by Sam James (previous) (diff)

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

Replying to thesamesam:

Hi folks,

https://github.com/django/django/commit/38e63c9e61152682f3ff982c85a73793ab6d3267 was applied to fix Python 3.12, but cpython upstream have backported the fix for https://github.com/python/cpython/issues/102549 to Python 3.11 too.

The Django patch will need adjusting to probably just allow both output messages (or sniff the Python minor/patch version).

Thanks! It's unfortunate, will fix this.

comment:13 by Sam James, 21 months ago

Cc: Sam James added

comment:14 by GitHub <noreply@…>, 21 months ago

In 2eb1f372:

Refs #34118 -- Fixed CustomChoicesTests.test_uuid_unsupported on Python 3.11.4+.

https://github.com/python/cpython/commit/5342f5e713e0cc45b6f226d2d053a8cde1b4d68e

Follow up to 38e63c9e61152682f3ff982c85a73793ab6d3267.

comment:15 by Mariusz Felisiak <felisiak.mariusz@…>, 21 months ago

In f6e0029:

[4.2.x] Refs #34118 -- Fixed CustomChoicesTests.test_uuid_unsupported on Python 3.11.4+.

https://github.com/python/cpython/commit/5342f5e713e0cc45b6f226d2d053a8cde1b4d68e

Follow up to 38e63c9e61152682f3ff982c85a73793ab6d3267.
Backport of 2eb1f37260f0e0b71ef3a77eb5522d2bb68d6489 from main

comment:16 by Mariusz Felisiak <felisiak.mariusz@…>, 21 months ago

In f55bcff9:

[4.1.x] Refs #34118 -- Fixed CustomChoicesTests.test_uuid_unsupported on Python 3.11.4+.

https://github.com/python/cpython/commit/5342f5e713e0cc45b6f226d2d053a8cde1b4d68e

Follow up to 38e63c9e61152682f3ff982c85a73793ab6d3267.

Backport of 2eb1f37260f0e0b71ef3a77eb5522d2bb68d6489 from main

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

In 5a6d4d3b:

Refs #34118, Refs #34504 -- Added backward incompatibility note about EmailBackend.ssl_context.

Follow up to 2848e5d0ce5cf3c31fe87525536093b21d570f69.

comment:18 by Mariusz Felisiak <felisiak.mariusz@…>, 20 months ago

In 4f343a1:

[4.2.x] Refs #34118, Refs #34504 -- Added backward incompatibility note about EmailBackend.ssl_context.

Follow up to 2848e5d0ce5cf3c31fe87525536093b21d570f69.
Backport of 5a6d4d3bfde07daab9777545694beb014c832264 from main

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

In fc9c90d9:

Refs #34118 -- Fixed FunctionalTests.test_cached_property_reuse_different_names() on Python 3.12+.

Python 3.12+ no longer wraps exceptions in set_name, see
https://github.com/python/cpython/commit/55c99d97e14618dfce41472dd4446f763b0da13f

comment:20 by Mariusz Felisiak <felisiak.mariusz@…>, 19 months ago

In bf5249fc:

[4.2.x] Refs #34118 -- Fixed FunctionalTests.test_cached_property_reuse_different_names() on Python 3.12+.

Python 3.12+ no longer wraps exceptions in set_name, see
https://github.com/python/cpython/commit/55c99d97e14618dfce41472dd4446f763b0da13f
Backport of fc9c90d9c4611d441d2617a7d74f622b1f520f7c from main

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

In da2f8e8:

Refs #34118 -- Improved sanitize_address() error message for tuple with empty strings.

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

In 62b83889:

Fixed #34731, Refs #34118 -- Replaced assertEquals() with assertEqual() in test_condition_with_func_and_lookup_outside_relation_name().

Signed-off-by: Michel Alexandre Salim <salimma@…>

comment:23 by Mariusz Felisiak, 15 months ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned
Triage Stage: Someday/MaybeAccepted

comment:24 by GitHub <noreply@…>, 14 months ago

In 20b7aac7:

Refs #34900, Refs #34118 -- Updated assertion in test_skip_class_unless_db_feature() test on Python 3.12.1+.

Python 3.12.1+ no longer includes skipped tests in the number of
running tests. Check out:

https://github.com/python/cpython/issues/110890#issuecomment-1763458686
https://github.com/python/cpython/pull/106588

comment:25 by Mariusz Felisiak <felisiak.mariusz@…>, 14 months ago

In 448510a9:

[5.0.x] Refs #34900, Refs #34118 -- Updated assertion in test_skip_class_unless_db_feature() test on Python 3.12.1+.

Python 3.12.1+ no longer includes skipped tests in the number of
running tests. Check out:

https://github.com/python/cpython/issues/110890#issuecomment-1763458686
https://github.com/python/cpython/pull/106588
Backport of 20b7aac7ca60b0352d926340622e618bcbee54a8 from main

comment:26 by Mariusz Felisiak <felisiak.mariusz@…>, 14 months ago

In a576ef9:

[4.2.x] Refs #34900, Refs #34118 -- Updated assertion in test_skip_class_unless_db_feature() test on Python 3.12.1+.

Python 3.12.1+ no longer includes skipped tests in the number of
running tests. Check out:

https://github.com/python/cpython/issues/110890#issuecomment-1763458686
https://github.com/python/cpython/pull/106588
Backport of 20b7aac7ca60b0352d926340622e618bcbee54a8 from main

comment:27 by Mariusz Felisiak <felisiak.mariusz@…>, 14 months ago

In e2922b0:

Refs #34118 -- Avoided repeat coroutine checks in MiddlewareMixin.

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

In 19c4052f:

Refs #34118 -- Used Python 3.12 for GitHub actions.

comment:29 by Mariusz Felisiak, 13 months ago

Has patch: set

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

In b5750b9f:

[4.2.x] Refs #34118 -- Fixed stacklevel in complex_setting_changed on Python 3.12.

This fix is unnecessary in Django 5.0 since
e83a88566a71a2353cebc35992c110be0f8628af because signals no longer use
sync_to_async().

comment:31 by Mariusz Felisiak <felisiak.mariusz@…>, 13 months ago

In f955c90:

Refs #34118 -- Added Python 3.12 to classifiers and tox.ini.

comment:32 by Mariusz Felisiak <felisiak.mariusz@…>, 13 months ago

In ecfea05:

Refs #34118 -- Doc'd Python 3.12 compatibility in Django 4.2.x.

comment:33 by Mariusz Felisiak <felisiak.mariusz@…>, 13 months ago

In c342b58:

[5.0.x] Refs #34118 -- Added Python 3.12 to classifiers and tox.ini.

Backport of f955c90488e1f32e6e38b3c956e937579d389fb2 from main

comment:34 by Mariusz Felisiak <felisiak.mariusz@…>, 13 months ago

In f721fb93:

[5.0.x] Refs #34118 -- Doc'd Python 3.12 compatibility in Django 4.2.x.

Backport of ecfea054ee2b8ddfa027459ff8b6aecba05facf7 from main

comment:35 by Mariusz Felisiak <felisiak.mariusz@…>, 13 months ago

In 233e2a9e:

[4.2.x] Refs #34118 -- Added Python 3.12 to classifiers and tox.ini.

Backport of f955c90488e1f32e6e38b3c956e937579d389fb2 from main.

comment:36 by Mariusz Felisiak <felisiak.mariusz@…>, 13 months ago

In 9afeb6b9:

[4.2.x] Refs #34118 -- Doc'd Python 3.12 compatibility in Django 4.2.x.

Backport of ecfea054ee2b8ddfa027459ff8b6aecba05facf7 from main.

comment:37 by Mariusz Felisiak, 13 months ago

Resolution: fixed
Status: assignedclosed

comment:38 by Mariusz Felisiak <felisiak.mariusz@…>, 11 months ago

In bc8471f0:

Refs #34900, Refs #34118 -- Updated assertion in test_skip_class_unless_db_feature() test on Python 3.12.2+.

Python 3.12.2 bring back the skipped tests in the number of running
tests. Refs
https://github.com/python/cpython/commit/0a737639dcd3b7181250f5d56694b192eaddeef0

comment:39 by Mariusz Felisiak <felisiak.mariusz@…>, 11 months ago

In 1ba5afa:

[5.0.x] Refs #34900, Refs #34118 -- Updated assertion in test_skip_class_unless_db_feature() test on Python 3.12.2+.

Python 3.12.2 bring back the skipped tests in the number of running
tests. Refs
https://github.com/python/cpython/commit/0a737639dcd3b7181250f5d56694b192eaddeef0

Backport of bc8471f0aac8f0c215b9471b594d159783bac19b from main

comment:40 by Mariusz Felisiak <felisiak.mariusz@…>, 11 months ago

In 86d8034:

[4.2.x] Refs #34900, Refs #34118 -- Updated assertion in test_skip_class_unless_db_feature() test on Python 3.12.2+.

Python 3.12.2 bring back the skipped tests in the number of running
tests. Refs
https://github.com/python/cpython/commit/0a737639dcd3b7181250f5d56694b192eaddeef0

Backport of bc8471f0aac8f0c215b9471b594d159783bac19b from main

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

In 338ec052:

Refs #35361 -- Added test for Email line length checks when dealing with surrogate pairs.

Refs #33173, #34118 and #34900.

comment:42 by Sarah Boyce <42296566+sarahboyce@…>, 5 months ago

In 83ec18b1:

[5.0.x] Refs #34118 -- Used Python 3.12 for GitHub actions.

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