Skip to content

Commit

Permalink
feat: add TZ validator to AuditModel (#247)
Browse files Browse the repository at this point in the history
feat: include support for sqladmin
Fixes #244
  • Loading branch information
cofin authored Aug 22, 2024
1 parent ed4568e commit fc1484b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions advanced_alchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
mapped_column,
orm_insert_sentinel,
registry,
validates,
)
from sqlalchemy.orm.decl_base import _TableArgsType as TableArgsType # pyright: ignore[reportPrivateUsage]

Expand Down Expand Up @@ -200,6 +201,12 @@ class AuditColumns:
)
"""Date/time of instance last update."""

@validates("created_at", "updated_at")
def validate_tz_info(self, _: str, value: datetime) -> datetime:
if value.tzinfo is None:
value = value.replace(tzinfo=timezone.utc)
return value


class BasicAttributes:
"""Basic attributes for SQLALchemy tables and queries."""
Expand Down

0 comments on commit fc1484b

Please sign in to comment.