Skip to content

Commit

Permalink
[ROMM-1452] Mark naive datetimes as UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
gantoine committed Jan 10, 2025
1 parent de74688 commit b8f7a06
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions backend/endpoints/responses/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from datetime import datetime, timezone

from pydantic import BaseModel as PydanticBaseModel
from pydantic import ConfigDict


class BaseModel(PydanticBaseModel):
"""Ensures all datetime fields include UTC timezone"""

model_config = ConfigDict(
json_encoders={
datetime: lambda dt: (
dt.isoformat()
if dt.tzinfo
else dt.replace(tzinfo=timezone.utc).isoformat()
)
}
)

0 comments on commit b8f7a06

Please sign in to comment.