Repository navigation
Handle DST gaps in make_aware - #10324
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10324 +/- ##
==========================================
+ Coverage 88.30% 88.31% +0.01%
==========================================
Files 153 153
Lines 19734 19743 +9
Branches 2286 2288 +2
==========================================
+ Hits 17427 17437 +10
Misses 2008 2008
+ Partials 299 298 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
auvipy
left a comment
There was a problem hiding this comment.
please cross check the test failures
There was a problem hiding this comment.
Pull request overview
This PR fixes celery.utils.time.make_aware() for ZoneInfo timezones during spring-forward DST gaps by detecting non-existent (“imaginary”) local datetimes and normalizing them via dateutil.tz.resolve_imaginary(), while preserving the existing fall-back ambiguous-time handling. This addresses the incorrect pre-transition UTC offset behavior reported in #10322 and adds a regression test for the gap case.
Changes:
- Add
_is_imaginary()and updatemake_aware()to resolve non-existent local times before ambiguous-time resolution. - Add a unit test covering a known US/Eastern spring-forward gap datetime (
2024-03-10 02:30).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
celery/utils/time.py |
Adds imaginary-time detection and uses resolve_imaginary() in make_aware() before ambiguity handling. |
t/unit/utils/test_time.py |
Adds a regression test ensuring spring-forward gap times are advanced and get the correct UTC offset. |
fe7e0e0 to
011d644
Compare
|
I cross-checked the reported failures. The two Codecov failures were in Current head 011d644 updates that assertion and also addresses the inline feedback on the |
|
Pushed af8a97d to cover the Codecov gap in the new Local verification:
|
af8a97d to
14731b6
Compare
for more information, see https://pre-commit.ci
|
Pushed a test-only follow-up in 14731b6 to cover the remaining make_aware imaginary-time fallback branches reported by Codecov. Verified locally:
The new GitHub run has lint/scan/smoke/pre-commit passing so far; the unit matrix is still running. |
|
Coverage follow-up is on the branch now. The Local verification on the current remote head: GitHub now has Codecov patch/project green and the unit shards green. The larger integration/smoke matrix is still running. |
|
Follow-up: current head |
|
as we also have a package named django-celery-beat which rely on this part of celery, we have to cross check if any adjustment also needed there or not |
|
Cross-checked
So I do not see a required |
Description
make_aware()currently treats spring-forward gap times as ambiguous forZoneInfotimezones, so a nonexistent local time like2024-03-10 02:30inUS/Easternkeeps the pre-transition offset instead of moving to the first real wall time after the gap.This updates the helper to detect imaginary datetimes before ambiguous datetimes and resolve them with
dateutil.tz.resolve_imaginary(). The existing ambiguous-time path remains unchanged for real fall-back times and custom timezone objects.Fixes #10322.
Tests
.venv\Scripts\python -m pytest t\unit\utils\test_time.py::test_make_aware::test_tz_when_zoneinfo_and_time_does_not_exist -q.venv\Scripts\python -m pytest t\unit\utils\test_time.py::test_make_aware -q.venv\Scripts\python -m pytest t\unit\utils\test_time.py t\unit\app\test_schedules.py -q.venv\Scripts\python -m flake8 celery\utils\time.py t\unit\utils\test_time.pyNote: I also tried
.venv\Scripts\python -m pytest t\unit -q, but the local minimal environment is missing optional dependencies used by unrelated tests (pydantic, Azure/Google/Boto libraries, DNS, cryptography, Redis provider pieces), so collection stops before running the full suite.