fix(domrf_kn): детерминированный sha256-fallback для flat_id (#1208) #1262
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#1262
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/domrf-kn-deterministic-flat-id-fallback"
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
Closes #1208 (P2 data-integrity, prod). Fallback
flat_idчерезhash()рандомизирован per-process → дубли строк вkn_flatsпри resume sweep'а.Bug
domrf_kn._norm_flat:401:hash(str)в CPython рандомизирован per-process (PYTHONHASHSEED нигде в репо/Dockerfile/celery не выставлен).Эффект:
resume_kn_runстартует в новом воркере,worker_readyhook). До 10 объектов после checkpoint перечитываются → квартиры безflatId(несколько на ЖК-объект, реально на проде есть) получают другой hash-id в новом процессе →ON CONFLICT (id, snapshot_date)(uq_kn_flats_id_snap) не срабатывает → дубли строк одной квартиры в одномsnapshot_date.supply_layers).Fix
abs(hash(elem)) % (2**63 - 1)→int.from_bytes(hashlib.sha256(elem)[:8], "big") % (2**63 - 1).sha256стабилен между процессами/перезапусками/архитектурами. 8 байт → BIGINT-fit, коллизии практически невозможны для domrf-elemId space.Test plan
test_domrf_kn_normalize.py: formula matches sha256, stable across calls, distinct elems→distinct ids, flatId wins over fallback, no-id→None, BIGINT-fit.pytest tests/services/scrapers/test_domrf_kn_normalize.py→ 6 passed.ruff check→ clean.Closes #1208