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
+7 -7
View File
@@ -4,7 +4,7 @@ import json as _json
import logging
import shutil
import uuid
from datetime import datetime
from datetime import UTC, datetime
from pathlib import Path
from sqlalchemy import func
@@ -183,8 +183,8 @@ async def create_profile(
design_prompt=data.design_prompt,
default_engine=default_engine,
personality=data.personality,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow(),
created_at=datetime.now(UTC),
updated_at=datetime.now(UTC),
)
db.add(db_profile)
@@ -244,7 +244,7 @@ async def add_profile_sample(
db.add(db_sample)
profile.updated_at = datetime.utcnow()
profile.updated_at = datetime.now(UTC)
db.commit()
db.refresh(db_sample)
@@ -403,7 +403,7 @@ async def update_profile(
profile.personality = data.personality
if data.default_engine is not None:
profile.default_engine = data.default_engine or None # empty string → NULL
profile.updated_at = datetime.utcnow()
profile.updated_at = datetime.now(UTC)
db.commit()
db.refresh(profile)
@@ -672,7 +672,7 @@ async def upload_avatar(
process_avatar(image_path, str(output_path))
profile.avatar_path = config.to_storage_path(output_path)
profile.updated_at = datetime.utcnow()
profile.updated_at = datetime.now(UTC)
db.commit()
db.refresh(profile)
@@ -703,7 +703,7 @@ async def delete_avatar(
avatar_path.unlink()
profile.avatar_path = None
profile.updated_at = datetime.utcnow()
profile.updated_at = datetime.now(UTC)
db.commit()