fix(parcels): SAVEPOINT around velocity compute → не abort outer tx
Production POST /parcels/{cad}/analyze падает с 500:
sqlalchemy.exc.InternalError: (psycopg.errors.InFailedSqlTransaction)
current transaction is aborted, commands ignored until end of transaction block
## Root cause
`compute_velocity()` SQL fails (probably на cad's без conkurrentов / sparse
sale_graph data) → exception caught в try/except → НО db.rollback() отсутствует
→ transaction остаётся в aborted state.
Следующая query (_geotech_risk на line 828) пытается выполниться → крашится
с InFailedSqlTransaction.
## Fix
Wrap velocity в `with db.begin_nested()` — SAVEPOINT pattern (consistent
with PR #124 pzz_loader fix). Failure внутри savepoint:
- Rollbacks ТОЛЬКО savepoint
- Outer transaction остаётся clean
- Subsequent queries (_geotech_risk и пр.) работают
Pattern matches feedback_subagent_delegation audit recommendation для
in-loop / per-section exception handling.
## Impact
POST /parcels/{cad}/analyze больше не 500 при velocity failure. Возвращает
`velocity: null` + остальные fields normal.
Refs: user report 2026-05-15 InFailedSqlTransaction
This commit is contained in:
parent
d0b8eda6ad
commit
b08597ba61
1 changed files with 7 additions and 3 deletions
|
|
@ -1808,11 +1808,15 @@ def analyze_parcel(
|
|||
pipeline_24mo = _aggregate_pipeline(pipeline_rows)
|
||||
|
||||
# D2 (#34): velocity-score — темп продаж конкурентов вокруг участка.
|
||||
# SAVEPOINT защищает outer transaction если velocity SQL падает —
|
||||
# иначе следующие queries (_geotech_risk и пр.) крашатся
|
||||
# с InFailedSqlTransaction.
|
||||
velocity_data: dict[str, Any] | None = None
|
||||
try:
|
||||
v_result = compute_velocity(db, parcel_geom_wkt=geom_wkt, radius_km=3.0)
|
||||
if v_result is not None:
|
||||
velocity_data = v_result.as_dict()
|
||||
with db.begin_nested():
|
||||
v_result = compute_velocity(db, parcel_geom_wkt=geom_wkt, radius_km=3.0)
|
||||
if v_result is not None:
|
||||
velocity_data = v_result.as_dict()
|
||||
except Exception as _ve:
|
||||
logger.warning("velocity compute failed for %s: %s", cad_num, _ve)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue