fix(api): /parcels/by-bbox 500 — area via ST_Area, drop missing land_category #347
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#347
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/by-bbox-cad-parcels-missing-cols"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
P0 — entry карта
/site-finderпадает: каждый bbox refetch → backend 500.Root cause
PR #336 (SF-B1) написал endpoint предполагая, что
cad_parcelsимеетarea_m2иland_category. На самом деле таблица в проде имеет только(cad_num, geom)— это сырой геом-кадастр из НСПД, обогащение из EGRN живёт в отдельной структуре (см. B5 follow-up).Проверено через postgres MCP:
Fix
area_m2→ST_Area(p.geom::geography)— даёт метры² с учётом сферической поправки (без cast на geography — было бы в градусах²).land_category→NULL::textplaceholder. EGRN-enrichment tracking: vaultcode/modules/site-finder/B5-egrn-contract.md(TBD).ORDER BY p.area_m2→ORDER BY ST_Area(p.geom::geography)чтобы крупные участки сверху.p.geom::geography— это column cast (не:bind::type), поэтому SQLAlchemy/psycopg3 рассматривает корректно.Verify
Inline test через postgres MCP по prod-bbox из user repro:
Запрос возвращает 8507 парцелей в bbox центра ЕКБ.
Acceptance
После deploy:
curl 'https://gendsgn.ru/api/v1/parcels/by-bbox?...'→ 200/site-finderкарта показывает CircleMarker'ы, no 500 spam в GlitchTipCloses GlitchTip issue 135 (
column p.area_m2 does not exist).Deep Code Review — verdict ✅ APPROVE
Status: APPROVE → merging (P0 prod 500 fix)
Files: 1 (P1:
backend/app/api/v1/parcels.py)Lines: +6 / -3
Head SHA:
2dd21f68Verification
DB schema (postgres MCP) —
public.cad_parcelsconfirmed:cad_num,geom, plusland_record_area,specified_area,declared_area,land_record_category_type, ... (29 cols total)area_m2orland_category→ PR #336 bug is realcad_parcels_geom_gistongeom(GIST) — used byST_IntersectsEXPLAIN on fixed SQL (bbox центр ЕКБ, LIMIT 100):
GIST index works, sort на ~10k rows acceptable, no
UndefinedColumn.Checks passed
p.geom::geography— column cast, не bind cast → psycopg v3 compliant (per.claude/rules/sql.md/backend.md)CAST(:x AS type)(min_lat/min_lon/max_lat/max_lon/user_id/limit) — no:x::typeST_Area(geography)возвращает m² на EPSG:4326 (spherical Vincenty) — корректная формулаParcelMapMarker.land_category: str | None(schemas/parcel.py:375) принимает NULLsafeArea/safeLandCategoryуже обрабатываютnull(на основе типов изapi-types.ts)ST_Area(geography)per-row на ~10k filtered rows + LIMIT 200 — sort cheapMinor (non-blocking, follow-up)
specified_area/declared_area/land_record_area(numeric) — это уже materialised area values, можно использоватьCOALESCE(specified_area, declared_area, land_record_area, ST_Area(geom::geography))чтобы избежать per-row ST_Area вычисления для большинства строк. Не блокирующее — текущий fix корректный.fixes/by-bbox-cad-parcels-schema-mismatch.mdс lessons learned (review #336 не сверил DB schema).Severity: ✅ APPROVE — merging now
Production 500s blocking
/site-findermap UX. Fix surgical, tested via EXPLAIN, no scope creep.