Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten up handling of time_created, time_updated. #893

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 11 additions & 2 deletions tiled/authn_database/orm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import uuid as uuid_module
from datetime import datetime, timezone

from sqlalchemy import (
JSON,
Expand Down Expand Up @@ -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):
Expand Down