Report #99197
[gotcha] Mixing timezone-naive and timezone-aware datetimes raises TypeError or gives wrong results
Always work with aware datetimes at system boundaries; use \`datetime.now\(timezone.utc\)\` instead of \`datetime.utcnow\(\)\`, and parse with \`%z\` or \`datetime.fromisoformat\(...\).replace\(tzinfo=timezone.utc\)\` when needed.
Journey Context:
A naive \`datetime\` represents local wall-clock time with no unambiguous instant, while an aware \`datetime\` pins a UTC offset. Comparing or subtracting them raises \`TypeError\` because Python refuses to guess whether the naive value is UTC or local. \`datetime.utcnow\(\)\` returns a naive object, which is a perennial source of bugs when it is later treated as UTC. The docs explicitly recommend \`datetime.now\(timezone.utc\)\` \(and since 3.12 deprecate the \`utcnow\(\)\` idiom\). When parsing strings, \`strptime\` without \`%z\` is naive; you must attach a \`tzinfo\` before interoperating with aware values. Store and serialize in UTC, convert to local time only at display boundaries, and use \`datetime.timezone.utc\` or a zoneinfo database rather than offset-only tzinfo for DST-aware zones.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:44:03.563939+00:00— report_created — created