fix(tradein): rehydrate POST-only fields on GET /estimate/{id} (#696) #710
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#710
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/696-get-estimate-rehydrate"
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
/estimate/{id}(shared-link, PDF reopen,?id=restore) возвращалprice_trend/last_scraped_at/avito_imv/dkp_corridorкак null — house_id не ререзолвился в GET-хендлере, derived-поля терялись. POST их возвращает.target_house_idререзолвится по адресу (tradein_normalize_short_addr) + geo-fallback 100м (паттерн из placement-history/house-analytics, вынесен в_resolve_target_house_id);price_trend/avito_imv(display-only anchor) /dkp_corridor— через существующие estimator-хелперы;last_scraped_at=created_at − data_freshness_minutes(оба поля персистятся; эквивалентноmax(scraped_at)на момент POST).cian_valuation,est_days_on_market— потенциальный follow-up.Test plan
ruff check— clean (line-100)pytest tests/test_estimate_idor.py— 23 passed (включая новыйtest_get_estimate_rehydrates_post_only_fields, проверяющий что 4 поля surface'ятся)pytest tests/test_api_avito_stage4a.py— 5 passed (no regression)?id=/ shared-link → тренд-чарт, IMV-маркер, ДКП-коридор, метка свежести присутствуютCloses #696
POST /estimate возвращает price_trend, last_scraped_at, avito_imv и dkp_corridor, но GET /{id} (shared-link, PDF reopen, ?id= restore) отдавал их null — house_id не ререзолвился в GET-хендлере, derived-поля терялись. Пересчитываем в хендлере из персистированного состояния (DDL не требуется): - target_house_id ререзолвится по address (tradein_normalize_short_addr) с geo-fallback 100м — тот же паттерн, что в placement-history/house-analytics; - price_trend / avito_imv (display-only anchor) / dkp_corridor — через существующие estimator-хелперы _fetch_price_trend / _fetch_house_imv_anchor / _fetch_dkp_corridor; - last_scraped_at реконструируется как created_at − data_freshness_minutes (оба поля персистятся; эквивалентно max(scraped_at) на момент POST). Всё best-effort: None при отсутствии данных — без регрессий относительно прежнего поведения. cian_valuation / est_days_on_market тоже POST-only на GET (вне scope #696 — потенциальный follow-up). Closes #696✅ APPROVE — staff+ review, no blocking issues.
Correctness-critical checks all PASS:
timedeltaimported (from datetime import UTC, date, datetime, timedelta) — no NameError._fetch_price_trend(db, target_house_id=),_fetch_dkp_corridor(db, address=, rooms=, area=),_fetch_house_imv_anchor(db, target_house_id=, rooms=, area=).created_atadded in this PR; address/lat/lon/area_m2/rooms/data_freshness_minutes already present).:x::typeCAST trap (CAST(:id AS uuid)correct), no injection.::geographycasts are on column/expression, consistent with existing geo-fallback in this file.Advisory follow-ups (non-blocking, doc-only):
last_scraped_at = created_at − freshnessis a sub-minute approximation of POST's exactmax(scraped_at). Fine for the "обновлено DD.MM HH:MM" UI; worth a one-line comment so it isn't mistaken for exact.row.address(raw) to_fetch_dkp_corridorwhile POST passesgeo.full_address(DaData-normalized). Near-always same street; DKP is advisory + graceful-None, so low risk.app.services.estimatormodule, so_resolve_target_house_idand the real helper signatures are NOT exercised — a real-DB integration test would be needed to cover house_id resolution. Acceptable for unit scope; established pattern in this file.Merging.