Skip to content

Replace deprecated datetime.utcnow() with datetime.now(UTC)#62

Merged
aidankhogg merged 1 commit into
dev/alphafrom
claude/obvious-fixes-g0hwvw
Jun 28, 2026
Merged

Replace deprecated datetime.utcnow() with datetime.now(UTC)#62
aidankhogg merged 1 commit into
dev/alphafrom
claude/obvious-fixes-g0hwvw

Conversation

@aidankhogg

Copy link
Copy Markdown
Contributor

Summary

This PR updates all datetime operations throughout the codebase to use the modern datetime.now(UTC) pattern instead of the deprecated datetime.utcnow() method. This change aligns with Python 3.12+ best practices and improves timezone awareness.

Key Changes

  • Import updates: Added UTC to all datetime imports across 15+ files
  • Method replacements: Systematically replaced all datetime.utcnow() calls with datetime.now(UTC) in:
    • Handler modules (substrate, DNS, PKI, mail, MinIO, app deployment)
    • Phase implementations (platform identity, inworld identity, ANDS, services, registries)
    • Core infrastructure (drift controller, PKI certificate rotation worker)
    • Event schema and API routes
    • Test files
  • Metrics fix: Corrected record_phase() context manager to properly record phase duration in both success and error cases using a finally block

Implementation Details

  • The UTC constant from the datetime module provides explicit timezone information
  • datetime.now(UTC) is the recommended replacement for datetime.utcnow() as of Python 3.12
  • All timestamp generation, event emission, and state tracking now use timezone-aware datetime objects
  • No functional behavior changes; this is purely a modernization of the datetime API usage

https://claude.ai/code/session_016VaT8U8zeepxGd7sKXdGDg

Python 3.13 deprecated datetime.utcnow() in favor of timezone-aware objects.
Replaced all occurrences with datetime.now(UTC) across:
- Handlers (substrate, DNS, PKI, mail, storage, app)
- Phases (platform identity, inworld identity, registries, services, ANDs)
- Core modules (drift controller, events)
- Workers (PKI cert rotation)
- API routes
- Tests

Also fixed record_phase() in metrics to record duration on exception,
not just on success.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016VaT8U8zeepxGd7sKXdGDg
@aidankhogg aidankhogg self-assigned this Jun 28, 2026
@aidankhogg aidankhogg added the bug Something isn't working label Jun 28, 2026
@aidankhogg aidankhogg marked this pull request as ready for review June 28, 2026 21:28
@aidankhogg aidankhogg merged commit af2bc22 into dev/alpha Jun 28, 2026
4 checks passed
@aidankhogg aidankhogg deleted the claude/obvious-fixes-g0hwvw branch June 28, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants