fix(analyze): district KeyError 500 (#994) + revive by-bbox tests #1029

Merged
bot-backend merged 1 commit from fix/994-district-keyerror-test-revival into main 2026-06-03 13:05:05 +00:00
Collaborator

Live-багфикс (#994) + оживление by-bbox тестов.

БАГ (из уже-смерженного #994): persist-call-site в analyze_parcel извлекал district через result_payload["district"]["district_name"] — но district-dict без этого ключа (реальные данные: частичный district-lookup) → KeyError ВНЕ best-effort SAVEPOINT (извлечение в call-site, не внутри persist) → 500 на LIVE /analyze. Фикс: .get("district_name") → None. Поймано оживлением analyze-сьюта.

Тест-инфра (сьют был нерабочим — потому баг и прошёл):

  • Ленивый импорт WeasyPrint в layout_tz_pdf.py+trade_in_pdf.py (паттерн report_pdf/snapshot_pdf). Eager top-level импорты делали app.main неимпортируемым на хостах без native-libs (macOS dev) → ломали СБОР всего api/v1-сьюта. WeasyPrint импортится при реальном рендере PDF.
  • tests/conftest.py: autouse-сброс app.dependency_overrides (anti-leak).
  • test_parcel_by_bbox.py: моки get_db переведены с patch() (no-op — FastAPI Depends держит оригинал) на dependency_overrides, явный X-Authenticated-User (RBAC), patch latest_run_dates, +тест last_analysis_date из latest-рана (#994). 5/5 зелёные.

⚠️ NOTE: возврат collectability вскрыл PRE-EXISTING рот в др. api/v1-сьютах (analyze/admin/best_layouts: RBAC-header + дрейф ассертов/моков) — это НЕ регрессии данного PR (были uncollectable), трекаются отдельно под suite-rehab + CI test-gate.

Refs #994.

**Live-багфикс (#994) + оживление by-bbox тестов.** **БАГ (из уже-смерженного #994):** persist-call-site в `analyze_parcel` извлекал district через `result_payload["district"]["district_name"]` — но district-dict без этого ключа (реальные данные: частичный district-lookup) → **KeyError ВНЕ best-effort SAVEPOINT** (извлечение в call-site, не внутри persist) → **500 на LIVE /analyze**. Фикс: `.get("district_name")` → None. Поймано оживлением analyze-сьюта. **Тест-инфра** (сьют был нерабочим — потому баг и прошёл): - Ленивый импорт WeasyPrint в `layout_tz_pdf.py`+`trade_in_pdf.py` (паттерн report_pdf/snapshot_pdf). Eager top-level импорты делали `app.main` неимпортируемым на хостах без native-libs (macOS dev) → ломали СБОР всего api/v1-сьюта. WeasyPrint импортится при реальном рендере PDF. - `tests/conftest.py`: autouse-сброс `app.dependency_overrides` (anti-leak). - `test_parcel_by_bbox.py`: моки get_db переведены с `patch()` (no-op — FastAPI Depends держит оригинал) на `dependency_overrides`, явный X-Authenticated-User (RBAC), patch latest_run_dates, +тест last_analysis_date из latest-рана (#994). 5/5 зелёные. ⚠️ **NOTE:** возврат collectability вскрыл PRE-EXISTING рот в др. api/v1-сьютах (analyze/admin/best_layouts: RBAC-header + дрейф ассертов/моков) — это НЕ регрессии данного PR (были uncollectable), трекаются отдельно под suite-rehab + CI test-gate. Refs #994.
bot-backend added 1 commit 2026-06-03 13:05:04 +00:00
fix(analyze): district KeyError 500 in #994 persist + revive by-bbox tests
All checks were successful
Deploy / changes (push) Successful in 5s
Deploy / build-frontend (push) Has been skipped
Deploy / build-backend (push) Successful in 1m31s
Deploy / build-worker (push) Successful in 2m28s
Deploy / deploy (push) Successful in 1m44s
c8ab3e8be9
LIVE BUG (from #994, already merged): the analysis_runs persist call-site in
analyze_parcel extracted district via result_payload["district"]["district_name"]
— but a district dict without that key (real data: partial district lookup)
raised KeyError OUTSIDE the best-effort SAVEPOINT (extraction is at the call
site, not inside persist_analysis_run) → 500 on the LIVE /analyze endpoint.
Fix: .get("district_name") → None instead of raising. Caught by reviving the
analyze test suite (below).

Test-infra (the suite was un-runnable, which is why the bug shipped):
- Lazy-import WeasyPrint in layout_tz_pdf.py + trade_in_pdf.py (matches the
  existing report_pdf.py / snapshot_pdf.py pattern). The eager top-level imports
  made `app.main` (→ parcels/trade_in routers) un-importable on hosts without
  WeasyPrint native libs (e.g. macOS dev), breaking pytest COLLECTION of the
  whole api/v1 suite. WeasyPrint is still imported when a PDF is actually rendered.
- tests/conftest.py: autouse fixture clears app.dependency_overrides after each
  test (anti-leak — a leaked get_db override caused real-DB connection attempts).
- test_parcel_by_bbox.py: rewrite get_db mocking from patch("...get_db") (a no-op
  — FastAPI Depends holds the original ref) to app.dependency_overrides[get_db],
  add explicit X-Authenticated-User header (RBAC gate), patch latest_run_dates,
  + a new test asserting last_analysis_date from a latest run (#994). 5/5 green.

NOTE: reviving collectability exposes PRE-EXISTING rot in other api/v1 suites
(analyze/admin/best_layouts: RBAC-header + stale-assertion/mock drift) — those
are NOT regressions from this PR (they were uncollectable before) and are
tracked separately for a deliberate suite-rehab + CI test-gate effort.

Refs #994.
bot-backend merged commit c8ab3e8be9 into main 2026-06-03 13:05:05 +00:00
bot-backend deleted branch fix/994-district-keyerror-test-revival 2026-06-03 13:05:05 +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#1029
No description provided.