Skip to content

datetime.utcnow() deprecated in Python 3.12+ (readiness-check.py post_heartbeat path) #68

Description

@ehsan6sha

Summary

readiness-check.py:1059 uses datetime.utcnow(), which is deprecated in Python 3.12 and scheduled for removal in a future version. Surfaces as a DeprecationWarning on every readiness-check cycle on hosts running Python 3.12+.

Repro

python -m pytest tests/test_state_files_and_events.py -q
# warnings.warn output:
# E:\GitHub\fula-ota\docker\fxsupport\linux\readiness-check.py:1059:
#   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).

Suggested fix

from datetime import datetime, timezone

# was:
timestamp = datetime.utcnow().isoformat(timespec=milliseconds) + Z

# replace with:
timestamp = datetime.now(timezone.utc).isoformat(timespec=milliseconds).replace(+00:00, Z)

Or, cheaper:

timestamp = datetime.now(timezone.utc).strftime(%Y-%m-%dT%H:%M:%S.%f)[:-3] + Z

Why it matters

  • Today: cosmetic noise in test output.
  • When the lab device''s Python is upgraded past whichever release actually removes utcnow(): TypeError at runtime in post_heartbeat() → heartbeat fails silently → discovery thinks device is dead.

Scope

  • File: docker/fxsupport/linux/readiness-check.py:1059 (post_heartbeat) — and any other datetime.utcnow() callers in the same file (grep first).
  • Small surgical fix; one PR.

Discovered during

Blox AI plan, surfaced in pytest warnings during Phase 13/14 cycles, 2026-05-24.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions