"""What the database has to keep true whatever dialect is under it.""" from datetime import datetime, timedelta, timezone from sqlmodel import Session, select from fluksio.core.db import engine from fluksio.models import EngineEvent # The `db` fixture is session-scoped and autouse, so the schema is already there. def test_a_stored_instant_comes_back_aware_and_in_utc() -> None: """SQLite stores no offset, so the column type has to put one back. Without it a timestamp read from the database is naive: comparing it to `datetime.now(timezone.utc)` raises, and serialising it hands the frontend a time with no zone, which it reads as local. """ stamp = datetime(2026, 8, 21, 15, 30, tzinfo=timezone(timedelta(hours=2))) with Session(engine) as session: session.add( EngineEvent(ts=stamp, type="node_error", flow="tz", node="n", detail="") ) session.commit() with Session(engine) as session: stored = session.exec(select(EngineEvent).where(EngineEvent.flow == "tz")).one() assert stored.ts.tzinfo is not None assert stored.ts.utcoffset() == timedelta(0) assert stored.ts == stamp # And it still compares against an aware "now" rather than raising. assert stored.ts < datetime.now(timezone.utc)