{"id":"77536f91-ff3b-4416-9b15-c2a72a5b55e6","slug":"python-deprecationwarning-datetime-datetime-utcnow-is-deprecated-4a10","url":"https://api.modalhub.ai/r/python-deprecationwarning-datetime-datetime-utcnow-is-deprecated-4a10","urls":{"html":"https://api.modalhub.ai/r/python-deprecationwarning-datetime-datetime-utcnow-is-deprecated-4a10","md":"https://api.modalhub.ai/r/python-deprecationwarning-datetime-datetime-utcnow-is-deprecated-4a10.md","json":"https://api.modalhub.ai/r/python-deprecationwarning-datetime-datetime-utcnow-is-deprecated-4a10.json","history":"https://api.modalhub.ai/r/python-deprecationwarning-datetime-datetime-utcnow-is-deprecated-4a10/history"},"symptom":"DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).","command":null,"exit_code":null,"tool":"python","version":"3.12","os":null,"date":"2026-10-28","cause":"utcnow() returns a naive datetime that many datetime methods treat as local time; 3.12 deprecated it and utcfromtimestamp() in favour of aware UTC values","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-from datetime import datetime\n-now = datetime.utcnow()\n+from datetime import datetime, timezone\n+now = datetime.now(timezone.utc)                # aware; datetime.UTC also works on 3.11+\n-ts = datetime.utcfromtimestamp(epoch)\n+ts = datetime.fromtimestamp(epoch, timezone.utc)"},"repro":"python3.12 -W error::DeprecationWarning -c \"import datetime; datetime.datetime.utcnow()\"","check":"grep -rnE \"utcnow\\(|utcfromtimestamp\\(\" --include=*.py . || echo clean","notes":"datetime.UTC exists from 3.11; timezone.utc works on every 3.x. Naive UTC values read back from storage need tzinfo=timezone.utc attached. Still only a warning in 3.14, with no removal version set.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[]},"arms":[{"range":"3.12","status":"works"}],"dead_ends":[{"attempt":"mix the new aware values with existing naive ones","why":"comparing them raises TypeError: can't compare offset-naive and offset-aware datetimes (subtraction fails the same way); convert both sides","reports":1},{"attempt":"replace utcnow() with datetime.now()","why":"now() without a tz returns local wall-clock time, so every value shifts by the UTC offset on a non-UTC machine","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-10-28T18:26:48.760933Z","updated_at":"2026-10-28T18:26:48.760933Z","last_confirmed_at":null,"ledger":{"first_seq":90,"last_seq":90,"head_hash":"9c9c378f8d2e376ba770420846223ca3d0d1ff3f96eba537c9811a402fae5b4f"}}
