fix: normalize date-bucket keys for Postgres dashboard charts

Dashboard charts (activity, message-activity, node-count) rendered as
flat zeros on Postgres because func.date() returns a str on SQLite but
a datetime.date on Postgres — the dict lookup by string key always
missed. Fixed with a dialect-neutral _date_bucket_key() helper and
pinned the Postgres session timezone to UTC at the engine level.

Also adds dual-backend test infrastructure (TEST_DATABASE_BACKEND env
var), per-worker Postgres databases for pytest-xdist isolation, and
strengthened regression tests asserting non-zero date buckets.
This commit is contained in:
Louis King
2026-06-16 21:16:00 +01:00
parent d4d55b16d9
commit cf5add9924
10 changed files with 763 additions and 41 deletions
+12 -2
View File
@@ -95,13 +95,23 @@ class TestListProfiles:
api_db_session.add(adoption)
api_db_session.commit()
api_db_session.execute(text("PRAGMA foreign_keys=OFF"))
# Temporarily disable FK enforcement to simulate an orphaned adoption
# (node deleted while the adoption record persists). SQLite uses
# PRAGMA; Postgres uses session_replication_role = replica.
dialect = api_db_session.bind.dialect.name # type: ignore[union-attr]
if dialect == "postgresql":
api_db_session.execute(text("SET session_replication_role = replica"))
else:
api_db_session.execute(text("PRAGMA foreign_keys=OFF"))
api_db_session.execute(
text("DELETE FROM nodes WHERE id = :id"),
{"id": sample_node.id},
)
api_db_session.commit()
api_db_session.execute(text("PRAGMA foreign_keys=ON"))
if dialect == "postgresql":
api_db_session.execute(text("SET session_replication_role = DEFAULT"))
else:
api_db_session.execute(text("PRAGMA foreign_keys=ON"))
response = client_no_auth.get(
"/api/v1/user/profiles",