mirror of
https://github.com/ipnet-mesh/meshcore-hub.git
synced 2026-07-06 18:01:17 +02:00
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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user