feat(velocity): migrate D2 sales source → objective_corpus_room_month (#156) #157

Closed
lekss361 wants to merge 4 commits from feat/migrate-velocity-to-objective-data into main
2 changed files with 76 additions and 57 deletions
Showing only changes of commit c3cafefb1a - Show all commits

View file

@ -1658,6 +1658,7 @@ def analyze_parcel(
"lon": centroid_lon, "lon": centroid_lon,
} }
try: try:
with db.begin_nested():
zoning_row = ( zoning_row = (
db.execute( db.execute(
text(""" text("""
@ -1692,6 +1693,7 @@ def analyze_parcel(
success_recommendation: dict[str, Any] | None = None success_recommendation: dict[str, Any] | None = None
if district_row: if district_row:
try: try:
with db.begin_nested():
success_rows = ( success_rows = (
db.execute( db.execute(
text(""" text("""

View file

@ -126,6 +126,13 @@ def compute_velocity(
) )
except Exception: except Exception:
logger.exception("velocity: competitor query failed for wkt=%s", parcel_geom_wkt[:80]) logger.exception("velocity: competitor query failed for wkt=%s", parcel_geom_wkt[:80])
# КРИТИЧНО: rollback aborted transaction чтобы caller (analyze_parcel)
# мог продолжить выполнять последующие queries. Иначе caller получает
# cascade InFailedSqlTransaction на следующей SQL execute.
try:
db.rollback()
except Exception:
pass
return None return None
if not comp_rows: if not comp_rows:
@ -186,6 +193,11 @@ def compute_velocity(
) )
except Exception: except Exception:
logger.exception("velocity: sale_graph query failed for obj_ids=%s", obj_ids[:5]) logger.exception("velocity: sale_graph query failed for obj_ids=%s", obj_ids[:5])
# КРИТИЧНО: rollback aborted transaction (см. competitor query комментарий)
try:
db.rollback()
except Exception:
pass
return None return None
if not sales_rows: if not sales_rows:
@ -311,6 +323,11 @@ def _get_ekb_median(db: Session, months_window: int = 6) -> float | None:
) )
except Exception: except Exception:
logger.warning("velocity: ekb_median query failed, using fallback") logger.warning("velocity: ekb_median query failed, using fallback")
# КРИТИЧНО: rollback aborted transaction
try:
db.rollback()
except Exception:
pass
return None return None
if row and row["median"] is not None: if row and row["median"] is not None: