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
lekss361 commented 2026-05-15 05:26:46 +00:00 (Migrated from github.com)

Bug

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 (например на sparse sale_graph) → exception caught → НО db.rollback() отсутствует → transaction остаётся в aborted state. Следующая query (_geotech_risk на line 828) → InFailedSqlTransaction.

Fix

Wrap velocity в with db.begin_nested() — SAVEPOINT pattern (consistent с PR #124 pzz_loader fix).

try:
    with db.begin_nested():  # ← SAVEPOINT
        v_result = compute_velocity(db, ...)
        ...
except Exception as _ve:
    logger.warning(...)
    # savepoint auto-rollback'нут, outer tx clean

Impact

POST /parcels/{cad}/analyze больше не 500. На failure velocity → velocity: null.

После merge — deploy auto-redeploys backend, прод работает.

Refs: user report 2026-05-15

## Bug 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 (например на sparse sale_graph) → exception caught → НО **db.rollback() отсутствует** → transaction остаётся в aborted state. Следующая query (_geotech_risk на line 828) → InFailedSqlTransaction. ## Fix Wrap velocity в `with db.begin_nested()` — SAVEPOINT pattern (consistent с PR #124 pzz_loader fix). ```python try: with db.begin_nested(): # ← SAVEPOINT v_result = compute_velocity(db, ...) ... except Exception as _ve: logger.warning(...) # savepoint auto-rollback'нут, outer tx clean ``` ## Impact `POST /parcels/{cad}/analyze` больше не 500. На failure velocity → `velocity: null`. После merge — deploy auto-redeploys backend, прод работает. Refs: user report 2026-05-15
lekss361 commented 2026-05-15 05:29:06 +00:00 (Migrated from github.com)

Final review (SHA b08597b, CI )

Корректный fix для psycopg InFailedSqlTransaction после PR #146 velocity integration:

Root cause: PG abort'ит entire transaction на любой SQL error; Python try/except ловит Python exception но connection остаётся в aborted state → следующая query крашится
db.begin_nested() SAVEPOINT — standard fix, auto-rollback на exception оставляет outer tx clean (velocity_data = None, остальной flow продолжается)
Consistent с PR #124 (pzz_loader) — reuse идиомы из codebase
Inline-комментарий объясняет why этот pattern нужен
Tiny surgical (+7/-3), CI зелёный

approve merge

## Final review (SHA `b08597b`, CI ✅) Корректный fix для psycopg `InFailedSqlTransaction` после PR #146 velocity integration: ✅ **Root cause**: PG abort'ит entire transaction на любой SQL error; Python try/except ловит Python exception но connection остаётся в aborted state → следующая query крашится ✅ **`db.begin_nested()` SAVEPOINT** — standard fix, auto-rollback на exception оставляет outer tx clean (`velocity_data = None`, остальной flow продолжается) ✅ **Consistent с PR #124 (pzz_loader)** — reuse идиомы из codebase ✅ Inline-комментарий объясняет why этот pattern нужен ✅ Tiny surgical (+7/-3), CI зелёный approve merge
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#154
No description provided.