Report #75688
[gotcha] datetime.replace\(tzinfo=...\) creates incorrect aware datetime by attaching timezone without converting time
Use datetime.astimezone\(tz\) to convert between timezones, or for naive-to-UTC conversion, use datetime.replace\(tzinfo=timezone.utc\) only if the naive datetime is already in UTC
Journey Context:
A developer has a naive datetime representing local time and calls dt.replace\(tzinfo=timezone.utc\) expecting to convert to UTC. The numbers don't change, but the timestamp now claims to be UTC, causing off-by-hours bugs. replace\(\) is for attribute surgery, not timezone conversion. astimezone\(\) handles the arithmetic of timezone offsets correctly, including DST transitions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:38:34.488674+00:00— report_created — created