fix(cron): naive ISO timestamps stored without timezone — jobs fire at wrong time#1729
Merged
fix(cron): naive ISO timestamps stored without timezone — jobs fire at wrong time#1729
Conversation
User-provided ISO timestamps like '2026-02-03T14:00' (no timezone) were stored naive. The _ensure_aware() helper at check time interprets naive datetimes using the current system timezone, but if the system timezone changes between job creation and checking, the job fires at the wrong time. Fix: call dt.astimezone() at parse time to immediately stamp the datetime with the local timezone. The stored value is now always timezone-aware, so it's stable regardless of later timezone changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
User-provided ISO timestamps like
2026-02-03T14:00(no timezone) were stored as naive datetimes. At check time,_ensure_aware()interprets them using the current system timezone. If the system timezone changes between job creation and checking (e.g., server migration, DST change), the job fires at the wrong wall-clock time.What changed
cron/jobs.py: Inparse_schedule(), calldt.astimezone()on naive datetimes to immediately stamp them with the local timezone. The storedrun_atvalue is now always timezone-aware (e.g.,2026-02-03T14:00:00-08:00), so it's stable regardless of later timezone changes.Timestamps that already include timezone info (e.g.,
2026-02-03T14:00+02:00orZ) are unaffected.Test plan
python -m pytest tests/cron/ -n0 -q→ 54 passed, 3 skipped ✔2026-06-01T09:00→ verify storedrun_atincludes timezone offset