Report #99
[gotcha] datetime.replace\(tzinfo=...\) attaches a timezone instead of converting the time
Use datetime.astimezone\(tz\) to convert an aware datetime to another timezone. For naive datetimes, first localize them with tz.localize\(\) \(pytz\) or create them timezone-aware from the start; never use replace\(\) to assign tzinfo to a naive datetime whose value is already in a local wall-clock sense.
Journey Context:
replace\(\) is a field-level override, not a unit conversion. If you parse '2024-01-01 10:00:00' as a naive local time and then call .replace\(tzinfo=timezone.utc\), you silently claim the wall-clock value is UTC, shifting the instant by hours. This is one of the most common timezone bugs in Python web services. astimezone\(\) adjusts the underlying instant while preserving the represented moment; replace\(\) merely relabels it. pytz's localize\(\) is the canonical way to interpret a naive datetime in a zone because it handles ambiguous times \(DST transitions\) correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-12T09:14:16.786737+00:00— report_created — created