Opened 13 months ago

Closed 11 days 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 (37)

comment:1 Changed 13 months ago by bcail

Cc: bcail added

comment:2 Changed 13 months ago by David Sanders

Cc: David Sanders added

comment:3 Changed 13 months ago by David Sanders

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 13 months ago by David Sanders (previous) (diff)

comment:4 Changed 13 months ago by bcail

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

comment:5 Changed 13 months ago by GitHub <noreply@…>

In 67504ea5:

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

comment:6 Changed 13 months ago by GitHub <noreply@…>

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 Changed 12 months ago by GitHub <noreply@…>

In 32d70b2:

Refs #34118 -- Adopted asgiref coroutine detection shims.

Thanks to Mariusz Felisiak for review.

comment:8 Changed 11 months ago by GitHub <noreply@…>

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 Changed 8 months ago by GitHub <noreply@…>

In 38e63c9:

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

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

comment:10 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 8 months ago by Sam James

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 8 months ago by Sam James (previous) (diff)

comment:12 in reply to:  11 Changed 8 months ago by Mariusz Felisiak

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 Changed 8 months ago by Sam James

Cc: Sam James added

comment:14 Changed 8 months ago by GitHub <noreply@…>

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 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 7 months ago by GitHub <noreply@…>

In 5a6d4d3b:

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

Follow up to 2848e5d0ce5cf3c31fe87525536093b21d570f69.

comment:18 Changed 7 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 6 months ago by GitHub <noreply@…>

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 Changed 6 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 5 months ago by GitHub <noreply@…>

In da2f8e8:

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

comment:22 Changed 4 months ago by GitHub <noreply@…>

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 Changed 2 months ago by Mariusz Felisiak

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

comment:24 Changed 7 weeks ago by GitHub <noreply@…>

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 Changed 7 weeks ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 7 weeks ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 5 weeks ago by Mariusz Felisiak <felisiak.mariusz@…>

In e2922b0:

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

comment:28 Changed 12 days ago by GitHub <noreply@…>

In 19c4052f:

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

comment:29 Changed 12 days ago by Mariusz Felisiak

Has patch: set

comment:30 Changed 11 days ago by GitHub <noreply@…>

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 Changed 11 days ago by Mariusz Felisiak <felisiak.mariusz@…>

In f955c90:

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

comment:32 Changed 11 days ago by Mariusz Felisiak <felisiak.mariusz@…>

In ecfea05:

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

comment:33 Changed 11 days ago by Mariusz Felisiak <felisiak.mariusz@…>

In c342b58:

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

Backport of f955c90488e1f32e6e38b3c956e937579d389fb2 from main

comment:34 Changed 11 days ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 11 days ago by Mariusz Felisiak <felisiak.mariusz@…>

In 233e2a9e:

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

Backport of f955c90488e1f32e6e38b3c956e937579d389fb2 from main.

comment:36 Changed 11 days ago by Mariusz Felisiak <felisiak.mariusz@…>

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 Changed 11 days ago by Mariusz Felisiak

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top