fix(parcels): SAVEPOINT around velocity → не abort outer tx (analyze 500 fix) #154

Merged
lekss361 merged 1 commit from fix/velocity-savepoint-aborted-tx into main 2026-05-15 05:29:24 +00:00

View file

@ -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)