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 <noreply@anthropic.com>
This commit is contained in:
@@ -107,8 +107,12 @@ def _get_conn() -> duckdb.DuckDBPyConnection:
|
|||||||
|
|
||||||
|
|
||||||
async def fetch_analytics(sql: str, params: list | None = None) -> list[dict]:
|
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."""
|
"""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"
|
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():
|
def _query():
|
||||||
conn = _get_conn()
|
conn = _get_conn()
|
||||||
|
|||||||
Reference in New Issue
Block a user