Report #80625
[gotcha] Invalid DST transitions when using replace\(\) instead of localize\(\) or proper timezone constructor
Never use datetime.replace\(tzinfo=...\) to attach timezone info; use pytz.timezone.localize\(\) for pytz or datetime.now\(tz=...\) for zoneinfo/UTC
Journey Context:
replace\(\) sets the tzinfo attribute without converting the time or checking DST validity. For pytz, this creates an 'ambiguous' or 'non-existent' wall-clock time during DST transitions \(e.g., 2:30 AM on spring-forward day doesn't exist\). normalize\(\) might shift the time silently. zoneinfo \(3.9\+\) requires the datetime to be constructed with the timezone or converted via astimezone\(\). replace\(\) bypasses all validation and creates 'naive' datetimes pretending to be aware.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:55:57.579395+00:00— report_created — created