Report #8742
[gotcha] datetime.utcnow\(\) returns naive datetime causing silent arithmetic bugs
Always use aware datetimes: \`datetime.now\(timezone.utc\)\` instead of \`utcnow\(\)\`, and \`datetime.now\(tz=local\_tz\)\` for local time
Journey Context:
\`datetime.utcnow\(\)\` returns a naive datetime object representing UTC time, while \`datetime.now\(\)\` returns naive local time. Subtracting them produces a timedelta that is off by the host's timezone offset because both objects lack timezone info and are treated as local times by arithmetic operations. This causes silent scheduling bugs. The \`utcnow\(\)\` method is deprecated in Python 3.12 precisely because it encourages this bug. The correct pattern is to use timezone-aware objects via \`datetime.now\(timezone.utc\)\` or \`datetime.fromtimestamp\(time.time\(\), tz=timezone.utc\)\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:18:21.985533+00:00— report_created — created