Add Python 3.14 support#14375
Conversation
|
CI checks failed on this PR:
I'll investigate and push a fix. |
|
The morango integration test failure (and the cascading cancellations) was caused by I've removed Python 3.14 from the CI workflow matrices ( |
90286db to
d3cf2da
Compare
|
CI checks failed on this PR:
I'll investigate and push a fix. |
|
Fixed the PostgreSQL CI failure in The fix changes |
e037b76 to
dffae39
Compare
Build Artifacts
Smoke test screenshot |
|
CI checks failed on this PR:
I'll investigate and push a fix. |
Replace deprecated datetime.utcnow() and datetime.utcfromtimestamp() with timezone-aware equivalents using datetime.now(tz=timezone.utc) and datetime.fromtimestamp(tz=timezone.utc) to avoid DeprecationWarnings on Python 3.14. Guard locale.getdefaultlocale() with hasattr check for its removal in Python 3.15+. Add monkey-patch for Django 3.2's BaseContext.__copy__ which breaks on Python 3.14 because super() objects no longer support __dict__ attribute setting. Guard the import with try/except ImportError so pip install succeeds before Django is installed. Update CI matrices, tox.ini, and setup.py to include Python 3.14 with upper bound extended to <3.15. Fixes learningequality#13823 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
le-utils has no release supporting Python 3.14 yet (all 0.2.x versions specify Requires-Python <3.14), which causes pip install to fail. Remove 3.14 from the morango integration test matrix until le-utils publishes a compatible release. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The auth api module already imports `now` from django.utils.timezone, so use it instead of adding a new datetime.timezone import. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Match API response nodes to expected nodes by id instead of relying on positional ordering, since fixture data has duplicate lft values for sibling nodes causing nondeterministic ORDER BY results on PostgreSQL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dffae39 to
e729e9a
Compare
|
Fixed the Python 3.13 CI failure. The Fix: moved the |
|
closing in favour of #14395 |
Summary
datetime.utcnow()anddatetime.utcfromtimestamp()with timezone-aware equivalents usingdatetime.now(tz=timezone.utc)anddatetime.fromtimestamp(tz=timezone.utc)locale.getdefaultlocale()withhasattrcheck for its removal in Python 3.15+BaseContext.__copy__which breaks on Python 3.14 becausesuper()objects no longer support__dict__attribute settingmonkey_patch_base_context()withtry/except ImportErrorsopip installsucceeds before Django is installed<3.15)References
Fixes #13823
Reviewer guidance
kolibri/utils/env.py:146-167— Themonkey_patch_base_context()function is the most significant change. It replaces Django 3.2's broken__copy__implementation with one that usesobject.__new__+__dict__copy. Thetry/except ImportErrorguard is needed becauseset_env()runs duringpip installbefore Django is available. This patch can be removed when upgrading to Django 4.2+.kolibri/core/auth/api.py:1362andkolibri/plugins/facility/views.py:86— These usedatetime.now(tz=timezone.utc)directly rather thandjango.utils.timezone.now()because Django 3.2'snow()internally calls the deprecatedutcnow(), which would still trigger the Python 3.14 deprecation warning.kolibri/utils/i18n.py:83-87— Useshasattrguard rather thantry/except AttributeErrorto avoid masking unrelated errors.Test evidence
Python tests
Both test suites pass on Python 3.14.0. The
test_env_compat.pytests verify theBaseContext.__copy__monkey-patch works for bothBaseContextand itsRequestContextsubclass. The scheduler tests verify thedatetime.now()replacement in the naive-datetime-rejection test still correctly exercises the ValueError path.Acceptance Criteria
python_requiresupper bound extended to<3.15datetime.utcnow()/utcfromtimestamp()replaced with timezone-aware alternativeslocale.getdefaultlocale()guarded for Python 3.15+ removalBaseContext.__copy__monkey-patched for Python 3.14 compatibilitymonkey_patch_base_context()handles missing Django duringpip installtest/test_env_compat.py)AI usage
Claude Code implemented the Python 3.14 compatibility changes following patterns established in the existing
env.pymonkey-patches (monkey_patch_markdown,forward_port_cgi_module). The code was reviewed for reuse opportunities, quality, and efficiency using three parallel review passes. One bug was found and fixed during review: themonkey_patch_base_context()function needed atry/except ImportErrorguard becauseset_env()runs duringpip installbefore Django is available.🤖 Generated with Claude Code
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?