fix: replace stale analytics._conn checks with _db_path
dashboard/routes.py (4 places) and admin/routes.py still checked analytics._conn is not None after _conn was removed in the two-file refactor — causing AttributeError → 500 on every dashboard page. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,10 +53,9 @@ async def get_dashboard_stats() -> dict:
|
|||||||
# Analytics stats (DuckDB)
|
# Analytics stats (DuckDB)
|
||||||
analytics = {"commodity_count": 0, "min_year": None, "max_year": None}
|
analytics = {"commodity_count": 0, "min_year": None, "max_year": None}
|
||||||
try:
|
try:
|
||||||
from ..analytics import _conn as duckdb_conn
|
from ..analytics import _db_path, fetch_analytics
|
||||||
from ..analytics import fetch_analytics
|
|
||||||
|
|
||||||
if duckdb_conn is not None:
|
if _db_path:
|
||||||
rows = await fetch_analytics(
|
rows = await fetch_analytics(
|
||||||
"""
|
"""
|
||||||
SELECT COUNT(DISTINCT commodity_code) as commodity_count,
|
SELECT COUNT(DISTINCT commodity_code) as commodity_count,
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ async def index():
|
|||||||
user = g.user
|
user = g.user
|
||||||
plan = (g.get("subscription") or {}).get("plan", "free")
|
plan = (g.get("subscription") or {}).get("plan", "free")
|
||||||
|
|
||||||
if analytics._conn is not None:
|
if analytics._db_path:
|
||||||
results = await asyncio.gather(
|
results = await asyncio.gather(
|
||||||
analytics.get_price_latest(analytics.COFFEE_TICKER),
|
analytics.get_price_latest(analytics.COFFEE_TICKER),
|
||||||
analytics.get_cot_positioning_latest(analytics.COFFEE_CFTC_CODE),
|
analytics.get_cot_positioning_latest(analytics.COFFEE_CFTC_CODE),
|
||||||
@@ -193,7 +193,7 @@ async def supply():
|
|||||||
current_year = datetime.date.today().year
|
current_year = datetime.date.today().year
|
||||||
start_year = current_year - rng["years"]
|
start_year = current_year - rng["years"]
|
||||||
|
|
||||||
if analytics._conn is not None:
|
if analytics._db_path:
|
||||||
results = await asyncio.gather(
|
results = await asyncio.gather(
|
||||||
analytics.get_global_time_series(
|
analytics.get_global_time_series(
|
||||||
analytics.COFFEE_COMMODITY_CODE,
|
analytics.COFFEE_COMMODITY_CODE,
|
||||||
@@ -246,7 +246,7 @@ async def positioning():
|
|||||||
price_limit = rng["days"]
|
price_limit = rng["days"]
|
||||||
cot_weeks = rng["weeks"]
|
cot_weeks = rng["weeks"]
|
||||||
|
|
||||||
if analytics._conn is not None:
|
if analytics._db_path:
|
||||||
results = await asyncio.gather(
|
results = await asyncio.gather(
|
||||||
analytics.get_price_latest(analytics.COFFEE_TICKER),
|
analytics.get_price_latest(analytics.COFFEE_TICKER),
|
||||||
analytics.get_price_time_series(analytics.COFFEE_TICKER, limit=price_limit),
|
analytics.get_price_time_series(analytics.COFFEE_TICKER, limit=price_limit),
|
||||||
@@ -292,7 +292,7 @@ async def warehouse():
|
|||||||
stocks_latest = stocks_trend = aging_latest = byport_latest = byport_trend = None
|
stocks_latest = stocks_trend = aging_latest = byport_latest = byport_trend = None
|
||||||
stocks_trend = aging_latest = byport_trend = []
|
stocks_trend = aging_latest = byport_trend = []
|
||||||
|
|
||||||
if analytics._conn is not None:
|
if analytics._db_path:
|
||||||
if view == "stocks":
|
if view == "stocks":
|
||||||
results = await asyncio.gather(
|
results = await asyncio.gather(
|
||||||
analytics.get_ice_stocks_latest(),
|
analytics.get_ice_stocks_latest(),
|
||||||
|
|||||||
Reference in New Issue
Block a user