Skip to content

fix(cron): naive ISO timestamps stored without timezone — jobs fire at wrong time#1729

Merged
teknium1 merged 1 commit intomainfrom
fix/cron-timezone-naive-iso
Mar 17, 2026
Merged

fix(cron): naive ISO timestamps stored without timezone — jobs fire at wrong time#1729
teknium1 merged 1 commit intomainfrom
fix/cron-timezone-naive-iso

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

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: In parse_schedule(), call dt.astimezone() on naive datetimes to immediately stamp them with the local timezone. The stored run_at value 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:00 or Z) are unaffected.

Test plan

  • python -m pytest tests/cron/ -n0 -q → 54 passed, 3 skipped ✔
  • Create a job with 2026-06-01T09:00 → verify stored run_at includes timezone offset
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.
@teknium1 teknium1 merged commit fb20a9e into main Mar 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant