Fix SQL syntax error in generate_series date cast (SQLAlchemy text() parsing)

SQLAlchemy's text() parser treated the ':' in '::date' (PostgreSQL cast syntax)
as a second unbound parameter after :start/:end, producing malformed SQL and
crashing the scheduled Booking.com scrape silently with no history entry written.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-15 08:42:15 +00:00
parent 38b0c36923
commit 4b5b8b30ed

View file

@ -69,7 +69,7 @@ def _get_oldest_scraped_dates(db: Session, start: date, end: date, limit: int) -
text("""
SELECT s.rate_date::date AS rate_date,
MAX(r.scraped_at) AS last_scraped
FROM generate_series(:start::date, :end::date, '1 day'::interval) AS s(rate_date)
FROM generate_series(CAST(:start AS date), CAST(:end AS date), INTERVAL '1 day') AS s(rate_date)
LEFT JOIN booking_com_rates r ON r.rate_date = s.rate_date::date
GROUP BY s.rate_date
ORDER BY last_scraped ASC NULLS FIRST