From fad7c1dc287f105f766cfc8349c20485a7f8ad18 Mon Sep 17 00:00:00 2001 From: Edwin Eames Date: Fri, 27 Feb 2026 18:41:12 -0500 Subject: [PATCH] feat: add fallback to most recent prices when requested date has no data - When no prices exist for the requested date, query for the most recent available date and return those prices instead - Log informational message when falling back to alternate date --- app/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/main.py b/app/main.py index 6bed657..4b96c9f 100644 --- a/app/main.py +++ b/app/main.py @@ -144,6 +144,17 @@ async def get_stored_prices( CompanyPrice.scrape_date == date ).all() + # Fallback: if no prices for requested date, get most recent ones + if not prices: + latest_date_result = db.query(CompanyPrice.scrape_date).order_by( + CompanyPrice.scrape_date.desc() + ).first() + if latest_date_result: + prices = db.query(CompanyPrice).filter( + CompanyPrice.scrape_date == latest_date_result[0] + ).all() + logger.info(f"No prices for {date}, returning {len(prices)} prices from {latest_date_result[0]}") + return [ PriceRecord( company_name=p.company_name,