fix(tradein-estimator): restore CAST in IS NOT NULL predicates (revert audit #9, prod fix) #518

Merged
lekss361 merged 1 commit from fix/tradein-estimator-restore-cast into main 2026-05-24 12:35:29 +00:00

1 commit

Author SHA1 Message Date
lekss361
4a2a804296 fix(tradein-estimator): restore CAST in IS NOT NULL predicates (revert audit #9)
PR #509 removed CAST(:target_year AS integer) and CAST(:target_house_type AS text)
from the IS NOT NULL predicates in _fetch_analogs, citing audit finding #9 (perf).
This broke production: psycopg3 prepared statement could not determine $4 type
when target_house_type=None, raising AmbiguousParameter at plan time. The CAST
in the THEN branch is not enough — PG planner needs the type to evaluate
IS NOT NULL itself.

The inline comment at lines 814-816 explicitly documented this requirement;
PR #509 misread the audit finding. Per-row CAST cost on ≤300 rows is negligible
vs production breakage. Restoring CAST forms; THEN-branch CASTs untouched
(they were never removed).

Verified prod stack trace 2026-05-24 ~12:25 (target_year=1978, target_house_type=None).
2026-05-24 15:28:36 +03:00