fix(22k): quartirography — use f.flat_type not f.type (column doesn't exist) #312

Merged
lekss361 merged 1 commit from fix/22k-quartirography-column into main 2026-05-17 16:09:01 +00:00
Owner

Summary

Post-#310 hotfix. GET /api/v1/analytics/object/{obj_id}/quartirography возвращал HTTP 500 на live (verified: gendsgn.ru/api/v1/analytics/object/65136/quartirography).

Root cause

analytics_queries.py:988-989 использовал LOWER(f.type), но в domrf_kn_flats нет колонки type — реальная колонка flat_type (verified через information_schema.columns).

PostgreSQL → 42703 undefined_column → FastAPI → 500.

Fix

2-line change в object_flats_quartirography():

-WHEN f.rooms IS NULL OR LOWER(f.type) LIKE '%нежил%'
-    OR LOWER(f.type) LIKE '%nonliv%' THEN 'Нежилые'
+WHEN f.rooms IS NULL OR LOWER(f.flat_type) LIKE '%нежил%'
+    OR LOWER(f.flat_type) LIKE '%nonliv%' THEN 'Нежилые'

Verification (постgres-gendesign MCP)

Запрос отдаёт 4 bucket'a для Малевич obj=65136:

room_label total free area_min..max price_min..max
Нежилые 16 0 24.92..828.74
1-комн. 243 16 24.99..54.29 7.5–9.6M ₽
2-комн. 139 36 37.59..84.81 9.5–14.8M ₽
3-комн. 31 6 67.76..93.22 12.0–12.9M ₽

Why not caught earlier

22k worker не запускал endpoint против live DB — только статический lint pass. Pre-merge нет integration test для analytics endpoints.

Test plan

  • После deploy: curl https://gendsgn.ru/api/v1/analytics/object/65136/quartirography → HTTP 200 + JSON массив.
  • Frontend /analytics/objects/65136 — Квартирография table render'ит 4 строки.
## Summary Post-#310 hotfix. `GET /api/v1/analytics/object/{obj_id}/quartirography` возвращал **HTTP 500** на live (verified: gendsgn.ru/api/v1/analytics/object/65136/quartirography). ## Root cause `analytics_queries.py:988-989` использовал `LOWER(f.type)`, но в `domrf_kn_flats` **нет колонки `type`** — реальная колонка `flat_type` (verified через `information_schema.columns`). PostgreSQL → 42703 undefined_column → FastAPI → 500. ## Fix 2-line change в `object_flats_quartirography()`: ```diff -WHEN f.rooms IS NULL OR LOWER(f.type) LIKE '%нежил%' - OR LOWER(f.type) LIKE '%nonliv%' THEN 'Нежилые' +WHEN f.rooms IS NULL OR LOWER(f.flat_type) LIKE '%нежил%' + OR LOWER(f.flat_type) LIKE '%nonliv%' THEN 'Нежилые' ``` ## Verification (постgres-gendesign MCP) Запрос отдаёт 4 bucket'a для Малевич obj=65136: | room_label | total | free | area_min..max | price_min..max | |---|---|---|---|---| | Нежилые | 16 | 0 | 24.92..828.74 | — | | 1-комн. | 243 | 16 | 24.99..54.29 | 7.5–9.6M ₽ | | 2-комн. | 139 | 36 | 37.59..84.81 | 9.5–14.8M ₽ | | 3-комн. | 31 | 6 | 67.76..93.22 | 12.0–12.9M ₽ | ## Why not caught earlier 22k worker не запускал endpoint против live DB — только статический lint pass. Pre-merge нет integration test для analytics endpoints. ## Test plan - [ ] После deploy: `curl https://gendsgn.ru/api/v1/analytics/object/65136/quartirography` → HTTP 200 + JSON массив. - [ ] Frontend `/analytics/objects/65136` — Квартирография table render'ит 4 строки.
lekss361 added 1 commit 2026-05-17 16:05:32 +00:00
POST-merge bug — /api/v1/analytics/object/{id}/quartirography returned 500
because SQL referenced f.type, but domrf_kn_flats has flat_type column.

Verified via DB: query now returns 4 buckets (Нежилые/1-3-комн.) for obj=65136.

Affected endpoint: GET /api/v1/analytics/object/{obj_id}/quartirography
Author
Owner

Deep Code Review — verdict: APPROVE

Verified:

  • domrf_kn_flats columns (postgres MCP): есть flat_type (text), f.type отсутствует — fix корректен.
  • Anti-regression: grep "f\.type" по backend → пусто. Других вхождений нет.
  • Остальные .type (analytics_queries.py:1427, 2624) — это a.type для алиаса apartments, не related.
  • Симметрия: оба usage'а внутри CASE WHEN (строки 988-989) заменены.
  • Scope minimal: +2/-2, 1 файл, без side effects.

Smoke (Малевич obj=65136): 4 bucket'a (Нежилые/1-комн./2-комн./3-комн.), free/total/area/price корректны.

Lesson learned: static lint (ruff/mypy) не валидирует SQL column existence в text("""..."""). Для analytics endpoints стоит integration test с реальной (или fixture) DB, который дёргает endpoint и проверяет non-500. Тогда такие 42703 ловились бы в CI, а не на live.

Merged as hotfix.

## Deep Code Review — verdict: APPROVE **Verified:** - `domrf_kn_flats` columns (postgres MCP): есть `flat_type` (text), `f.type` отсутствует — fix корректен. - Anti-regression: `grep "f\.type"` по backend → пусто. Других вхождений нет. - Остальные `.type` (analytics_queries.py:1427, 2624) — это `a.type` для алиаса `apartments`, не related. - Симметрия: оба usage'а внутри `CASE WHEN` (строки 988-989) заменены. - Scope minimal: +2/-2, 1 файл, без side effects. **Smoke (Малевич obj=65136):** 4 bucket'a (Нежилые/1-комн./2-комн./3-комн.), free/total/area/price корректны. **Lesson learned:** static lint (ruff/mypy) не валидирует SQL column existence в `text("""...""")`. Для analytics endpoints стоит integration test с реальной (или fixture) DB, который дёргает endpoint и проверяет non-500. Тогда такие 42703 ловились бы в CI, а не на live. Merged as hotfix.
lekss361 merged commit fd2b09b806 into main 2026-05-17 16:09:01 +00:00
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#312
No description provided.