Make dashboard gather resilient to missing analytics tables

Use return_exceptions=True so a CatalogException from a single query
(e.g. table not yet populated in a fresh env) degrades gracefully
instead of crashing the whole dashboard render.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-02-20 23:33:39 +01:00
parent 2962bf5e3b
commit 88e408b279

View File

@@ -100,7 +100,7 @@ async def index():
# Fetch all analytics data in parallel (empty lists/None if DB not available) # Fetch all analytics data in parallel (empty lists/None if DB not available)
if analytics._conn is not None: if analytics._conn is not None:
time_series, top_producers, stu_trend, balance, yoy, cot_latest, cot_trend = 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,
["production", "exports", "imports", "ending_stocks", "total_distribution"], ["production", "exports", "imports", "ending_stocks", "total_distribution"],
@@ -111,7 +111,12 @@ async def index():
analytics.get_production_yoy_by_country(analytics.COFFEE_COMMODITY_CODE, limit=15), analytics.get_production_yoy_by_country(analytics.COFFEE_COMMODITY_CODE, limit=15),
analytics.get_cot_positioning_latest(analytics.COFFEE_CFTC_CODE), analytics.get_cot_positioning_latest(analytics.COFFEE_CFTC_CODE),
analytics.get_cot_index_trend(analytics.COFFEE_CFTC_CODE, weeks=104), analytics.get_cot_index_trend(analytics.COFFEE_CFTC_CODE, weeks=104),
return_exceptions=True,
) )
time_series, top_producers, stu_trend, balance, yoy, cot_latest, cot_trend = [
r if not isinstance(r, Exception) else (None if i == 5 else [])
for i, r in enumerate(results)
]
else: else:
time_series, top_producers, stu_trend, balance, yoy = [], [], [], [], [] time_series, top_producers, stu_trend, balance, yoy = [], [], [], [], []
cot_latest, cot_trend = None, [] cot_latest, cot_trend = None, []