fix(scrapers): write resolved house_id to listings.house_id_fk in realtime link hook #1727
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#1727
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/house-id-fk-realtime-link"
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
Active listings barely link to master
houses(avito 0/444, cian 7%) because the realtime hook resolves a house but never writes the FK to the listing.Root cause
base.py::_link_listing_to_housecallsmatch_or_create_house()(full Tier 0-3) for every saved listing, but writes the resolvedhouse_idONLY intolisting_sources.source_dataJSON — there is noUPDATE listings SET house_id_fk, and the listings INSERT/UPSERT never sets it either. Sohouse_id_fkis populated only by unscheduled batch jobs (063_*.sql,scripts/backfill_listing_sources.py). Every new/re-scraped active row stays NULL. (Yandex looked ~88% linked only because past manual backfills caught its ext_id rows.)Fix (base.py only)
After
match_or_create_house()returns a non-Nonehouse_id, inside the existing per-listing SAVEPOINT:listing_idalready passed into the function; mirrorsbackfill_listing_sources.py.IS DISTINCT FROMre-links stale rows + skips no-op writes. Matcher/JSON/Tier logic untouched. psycopg v3CAST(:x AS bigint).Now every scrape (avito/cian/yandex) links via the matcher's fingerprint+geo tiers (avito 93% / cian ~100% geo coverage), not just ext_id.
Test plan
pytest -k "save_listings or base or matching or link or house"→ 317 passed; ruff cleanhouse_id_fkclimbs after a sweep; + one-timepython -m scripts.backfill_listing_sources(drains existing NULL backlog)Refs #1188