fix(parcels): rename CTE overlaps → overlap_rows (#1196 regression of #1195)
All checks were successful
CI / changes (push) Successful in 7s
CI / changes (pull_request) Successful in 6s
Deploy / changes (push) Successful in 6s
Deploy / build-frontend (push) Has been skipped
Deploy / build-worker (push) Successful in 2m47s
Deploy / deploy (push) Successful in 1m12s
CI / frontend-tests (push) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / backend-tests (push) Successful in 6m28s
CI / backend-tests (pull_request) Successful in 6m25s
Deploy / build-backend (push) Successful in 1m45s

`OVERLAPS` — это PostgreSQL keyword (binary operator для time-periods —
`(start1,end1) OVERLAPS (start2,end2)`). Парсер ругается на `overlaps AS (...)`
в WITH-блоке с

  ERROR: syntax error at or near "overlaps"

→ exception → транзакция в aborted state → весь analyze пайплайн ниже
получает InFailedSqlTransaction (ird_overlays, persist, ird block) → фронт
видит data_available=False, neighbors=[]. Воспроизводится на КАЖДОМ
/analyze с момента мерджа PR #1195.

Mock-БД в pytest tests/api/v1/ синтаксис не проверяет — отсюда регрессия
прошла CI. Прямой psql-replay на проде:
  WITH neighbors AS (...), overlaps AS (...) → syntax error
  WITH neighbors AS (...), overlap_rows AS (...) → ok

Минимальная переименование CTE alias (4 строки: 2 в SQL + 1 в SELECT
column alias + 1 в Python `row["overlap_rows"]`). Семантика идентична PR #1195.

Memory: future-proofing — добавить интеграционный тест с реальной PG для
analyze hot-path (отдельный issue, не блокер этого hotfix).

Refs #1196
This commit is contained in:
Light1YT 2026-06-13 08:59:45 +05:00
parent 49b85ab1d6
commit 2b23a4b24b

View file

@ -620,7 +620,7 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str
ORDER BY distance_m ASC
LIMIT 30
),
overlaps AS (
overlap_rows AS (
SELECT cad_num,
building_name,
floors,
@ -637,6 +637,8 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str
ORDER BY overlap_m2 DESC NULLS LAST
LIMIT 5
)
-- CTE name `overlap_rows` (НЕ `overlaps`): `OVERLAPS` PG keyword
-- (binary operator для time-periods), парсер ругается на `overlaps AS (`.
SELECT
COALESCE(
(SELECT json_agg(row_to_json(n) ORDER BY n.distance_m ASC)
@ -645,9 +647,9 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str
) AS neighbors,
COALESCE(
(SELECT json_agg(row_to_json(o) ORDER BY o.overlap_m2 DESC NULLS LAST)
FROM overlaps o),
FROM overlap_rows o),
'[]'::json
) AS overlaps
) AS overlap_rows
"""),
{"wkt": geom_wkt, "our_cad": our_cad_num},
)
@ -655,7 +657,7 @@ def _neighbors_summary(db: Session, geom_wkt: str, our_cad_num: str) -> dict[str
.first()
)
neighbor_rows: list[dict[str, Any]] = list(row["neighbors"]) if row else []
overlap_row: list[dict[str, Any]] = list(row["overlaps"]) if row else []
overlap_row: list[dict[str, Any]] = list(row["overlap_rows"]) if row else []
except Exception as e:
logger.warning("neighbors query failed: %s", e)
return {"data_available": False, "note": f"neighbors query failed: {e}"}