From 4bad66c91aa8bfda368377a610383e0fd537e4ef Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Tue, 21 Jul 2026 14:53:54 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20revenue=20endpoint=20500=20=E2=80=94=20ro?= =?UTF-8?q?llback=20SQLAlchemy=20session=20after=20caught=20exceptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When forecast_covers_range or forecast_revenue_for_date throw DB exceptions, the swallowed exception leaves the async session in an aborted transaction state. Subsequent queries (DOW averages, per-date accom) then fail with InFailedSQLTransactionError. Adding db.rollback() in the except blocks resets the session so the fallback path can continue cleanly. Co-Authored-By: Claude Sonnet 4.6 --- backend/api/public.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/api/public.py b/backend/api/public.py index 86bc6f1..330860c 100644 --- a/backend/api/public.py +++ b/backend/api/public.py @@ -384,6 +384,7 @@ async def get_revenue_forecast( covers_by_date = {c["date"]: c for c in covers_data.get("data", [])} except Exception as e: logger.warning(f"Covers forecast failed: {e}") + await db.rollback() covers_by_date = {} # DOW averages from recent 8 weeks — fallback when covers gives zero for future dates @@ -446,6 +447,7 @@ async def get_revenue_forecast( accom_forecast = accom_otb + accom_pickup accom_prior_otb = accom_forecast_data.get('prior_year_otb_rev', 0) or 0 except Exception: + await db.rollback() accom_otb = accom_forecast = accom_prior_otb = 0 # Restaurant