Replace deprecated datetime.utcnow() with datetime.now(UTC) throughout

Python 3.12 deprecates datetime.utcnow() with a DeprecationWarning and
it will be removed in a future release. Replace all call-site usages in
services, routes, and utils with datetime.now(UTC), and replace the
SQLAlchemy ORM column defaults (which used the bare function reference
datetime.utcnow) with lambda: datetime.now(UTC) so that the returned
objects are timezone-aware and consistent with Python best practice.

Affected: database/models.py, services/{stories,history,profiles,
channels,export_import}.py, routes/{profiles,tasks}.py, utils/tasks.py
This commit is contained in:
Will Anderson
2026-10-03 09:26:05 +00:00
committed by jamiepine
parent 51f49dea19
commit 851defa859
9 changed files with 54 additions and 54 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ import io
import json as _json
import logging
import tempfile
from datetime import datetime
from datetime import UTC, datetime
from pathlib import Path
from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile
@@ -356,7 +356,7 @@ async def update_profile_effects(
else:
profile.effects_chain = None
profile.updated_at = datetime.utcnow()
profile.updated_at = datetime.now(UTC)
db.commit()
db.refresh(profile)
+3 -3
View File
@@ -1,6 +1,6 @@
"""Task and cache management endpoints."""
from datetime import datetime
from datetime import UTC, datetime
from fastapi import APIRouter
@@ -91,9 +91,9 @@ async def get_active_tasks():
try:
started_at = datetime.fromisoformat(timestamp_str.replace("Z", "+00:00"))
except (ValueError, AttributeError):
started_at = datetime.utcnow()
started_at = datetime.now(UTC)
else:
started_at = datetime.utcnow()
started_at = datetime.now(UTC)
active_downloads.append(
models.ActiveDownloadTask(