fix(tradein-estimator): atomic IMV link, batched yandex history, drop redundant CAST #509

Merged
lekss361 merged 1 commit from feat/tradein-estimator-tx-fixes into main 2026-05-24 11:18:13 +00:00

1 commit

Author SHA1 Message Date
lekss361
872c83caf5 fix(tradein-estimator): atomic IMV link, batched yandex history, drop redundant CAST
3 fixes inside services/estimator.py from 2026-05-24 audit:

* IMV link UPDATE moved inside main tx (finding #4) — closes race where two
  concurrent estimates sharing a cache_key could overwrite each other's
  estimate_id after the main commit.
* _save_yandex_history_items batched under single try/except (finding #5) —
  prior per-item db.rollback() destroyed the parent transaction; next
  iteration could run on a rolled-back session.
* Drop redundant CAST inside IS NOT NULL predicates in _fetch_analogs
  (finding #9) — CAST(NULL AS T) IS NOT NULL is equivalent to NULL IS NOT NULL
  but evaluates per-row. THEN-branch CASTs preserved (typed arithmetic).

test: update test_save_history_items_db_error_continues → batch rollback semantics
2026-05-24 14:01:02 +03:00