refactor: update timestamp handling to use timezone-aware datetime

This commit is contained in:
JSC
2025-07-04 19:20:56 +02:00
parent 4375718c2f
commit 1cd43a670d
5 changed files with 94 additions and 58 deletions

View File

@@ -2,6 +2,7 @@
from datetime import datetime
from typing import TYPE_CHECKING, Optional
from zoneinfo import ZoneInfo
from sqlalchemy import DateTime, ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
@@ -34,13 +35,13 @@ class UserOAuth(db.Model):
# Timestamps
created_at: Mapped[datetime] = mapped_column(
DateTime,
default=datetime.utcnow,
default=lambda: datetime.now(tz=ZoneInfo("UTC")),
nullable=False,
)
updated_at: Mapped[datetime] = mapped_column(
DateTime,
default=datetime.utcnow,
onupdate=datetime.utcnow,
default=lambda: datetime.now(tz=ZoneInfo("UTC")),
onupdate=lambda: datetime.now(tz=ZoneInfo("UTC")),
nullable=False,
)
@@ -107,7 +108,7 @@ class UserOAuth(db.Model):
oauth_provider.email = email
oauth_provider.name = name
oauth_provider.picture = picture
oauth_provider.updated_at = datetime.utcnow()
oauth_provider.updated_at = datetime.now(tz=ZoneInfo("UTC"))
else:
# Create new provider
oauth_provider = cls(