Skip to content

Replace deprecated datetime.utcnow() with timezone-aware datetime #811

@Tim020

Description

@Tim020

Issue Description

The test suite shows deprecation warnings for datetime.utcnow() which is scheduled for removal in a future Python version.

Deprecation Warning

DeprecationWarning: 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).

Affected Files

Based on test output, the following files use deprecated datetime.utcnow():

  1. controllers/api/show/script/script.py:260

    • Usage: revision.edited_at = datetime.utcnow()
  2. controllers/api/show/script/revisions.py:116

    • Usage: now_time = datetime.utcnow()
  3. controllers/api/show/shows.py:87

    • Usage: now_time = datetime.utcnow()

Recommended Fix

Replace all instances of:

datetime.utcnow()

With the timezone-aware alternative:

datetime.now(datetime.UTC)

This requires:

  • Import datetime from the standard library (already imported in these files)
  • Update all datetime.utcnow() calls to datetime.now(datetime.UTC)
  • Verify timezone handling is consistent across the application

Additional Investigation Needed

  • Search entire codebase for all datetime.utcnow() usages
  • Check if any database schema or ORM expects naive vs timezone-aware datetimes
  • Verify tests still pass after migration
  • Consider if any API responses need updating to maintain compatibility

Priority

Medium - Not breaking functionality currently, but should be addressed before Python deprecates the method entirely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    claudeIssues created by Claude

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions