Report #104234
[gotcha] Comparing or operating on tz-naive and tz-aware datetime objects raises TypeError
Always use timezone-aware datetimes. Use \`datetime.now\(timezone.utc\)\` for current time and parse with \`datetime.fromisoformat\(...\)\` with proper offset; or use \`pytz\`/\`zoneinfo\`. Normalise to UTC before comparisons.
Journey Context:
Python's datetime module strictly forbids mixing naive and aware objects in comparisons, arithmetic, or datetime.combine. This catches many bugs, but the silent failure \(TypeError\) can be surprising when dates come from different sources \(e.g., database returns naive, API returns aware\). The recommended pattern is to adopt a project convention: store everything as UTC-aware. Use \`datetime.replace\(tzinfo=timezone.utc\)\` to convert naive if you are certain it's UTC. Avoid \`pytz\`'s localize for simple cases; use \`zoneinfo\` in Python 3.9\+.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-19T20:05:07.753786+00:00— report_created — created