From cb799ff019892745902ec96c735fabe45ad3e79d Mon Sep 17 00:00:00 2001 From: Deeman Date: Sun, 22 Feb 2026 11:10:36 +0100 Subject: [PATCH] fix: analytics fetch_analytics returns [] when DB not configured The assert _db_path in fetch_analytics() would crash dashboard routes locally when SERVING_DUCKDB_PATH is unset or serving.duckdb doesn't exist yet. Change to graceful return [] so the app degrades cleanly. Also add SERVING_DUCKDB_PATH=../serving.duckdb to local .env so the web app will auto-connect once `materia pipeline run export_serving` has been run for the first time. Co-Authored-By: Claude Sonnet 4.6 --- web/src/beanflows/analytics.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web/src/beanflows/analytics.py b/web/src/beanflows/analytics.py index 374a1a0..c054c9c 100644 --- a/web/src/beanflows/analytics.py +++ b/web/src/beanflows/analytics.py @@ -107,8 +107,12 @@ def _get_conn() -> duckdb.DuckDBPyConnection: async def fetch_analytics(sql: str, params: list | None = None) -> list[dict]: - """Run a read-only DuckDB query off the event loop. Returns list of dicts.""" - assert _db_path, "Analytics DB not configured — call open_analytics_db() first" + """Run a read-only DuckDB query off the event loop. Returns list of dicts. + Returns empty list if analytics DB is not configured (SERVING_DUCKDB_PATH unset + or file missing at startup) — dashboard routes degrade gracefully. + """ + if not _db_path: + return [] def _query(): conn = _get_conn()