From 9a2101bdd1e9bc531a0da95d2cf7c46dda226885 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Wed, 19 Feb 2025 11:56:15 -0500 Subject: [PATCH 1/2] Tighten up handling of time_created, time_updated. --- tiled/authn_database/orm.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tiled/authn_database/orm.py b/tiled/authn_database/orm.py index adcc38465..10638e55f 100644 --- a/tiled/authn_database/orm.py +++ b/tiled/authn_database/orm.py @@ -1,5 +1,6 @@ import json import uuid as uuid_module +from datetime import datetime, timezone from sqlalchemy import ( JSON, @@ -87,10 +88,18 @@ class Timestamped: __mapper_args__ = {"eager_defaults": True} time_created = Column( - DateTime(timezone=True), server_default=func.now(), nullable=False + DateTime(timezone=True), + # server default is applied too late for SQLAlchemy... + default=datetime.now(timezone.utc), + # but a server default is good to have for other clients + # so add that as well + server_default=func.now(), + nullable=False, ) time_updated = Column( - DateTime(timezone=True), onupdate=func.now() + DateTime(timezone=True), + onupdate=func.now(), + nullable=True, ) # null until first update def __repr__(self): From 43e38dd70ec16d3fb270647ccee2135870b5d904 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Wed, 19 Feb 2025 11:57:02 -0500 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21e3a7aa9..e6b63c427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ Write the date in place of the "Unreleased" in the case a new version is release ### Maintenance - Run authentication tests againts PostgreSQL as well as SQLite. +- Tighten up handling of `time_created` and `time_updated` in authentication + database. ## 0.1.0-b18 (2024-02-18)