Fix revenue endpoint 500 — rollback SQLAlchemy session after caught exceptions
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 <noreply@anthropic.com>
This commit is contained in:
parent
71a385e670
commit
4bad66c91a
1 changed files with 2 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue