fix(test): test_849 expects 3 begin_nested/lot after upsert-reconcile SAVEPOINT (#1921)
All checks were successful
CI / changes (pull_request) Successful in 6s
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped

197068c (#1921) added a per-lot SAVEPOINT around the listings upsert to catch
IntegrityError on UNIQUE(source,source_id) (migration 133) and reconcile via UPDATE.
That's a legit 3rd begin_nested/lot (upsert + snapshot + hook), so the test's
== 2*len(lots) proxy was stale → red main gate blocking all tradein deploys.
Hook itself still opens no inner SAVEPOINT (base.py:715) — test intent preserved.
This commit is contained in:
Light1YT 2026-06-26 22:22:32 +05:00
parent d89210200b
commit 731f5538a5

View file

@ -309,13 +309,16 @@ class TestSingleSavepointBatchIsolation:
save_listings(db, lots)
# save_listings calls begin_nested once per lot for the snapshot
# and once per lot for the hook — so 2 * len(lots) total.
# If _link_listing_to_house opens an INNER begin_nested too,
# the count would be > 2 * len(lots).
# (snapshot SAVEPOINT + hook SAVEPOINT = 2 per lot, no extra inner)
assert db.begin_nested.call_count == 2 * len(lots), (
f"Expected exactly 2 begin_nested per lot (snapshot + hook outer), "
# save_listings calls begin_nested THREE times per lot:
# 1) upsert SAVEPOINT — ловит IntegrityError на UNIQUE(source,source_id)
# (migration 133) при dedup_hash-дрейфе → rollback + прямой UPDATE (#1921);
# 2) snapshot SAVEPOINT;
# 3) hook SAVEPOINT (_link_listing_to_house).
# If _link_listing_to_house opened an INNER begin_nested too,
# the count would be > 3 * len(lots). The intent of this test (no double-nesting
# INSIDE the hook) holds — base.py keeps exactly one SAVEPOINT level in the hook.
assert db.begin_nested.call_count == 3 * len(lots), (
f"Expected exactly 3 begin_nested per lot (upsert + snapshot + hook outer), "
f"got {db.begin_nested.call_count} — inner SAVEPOINT may still be present"
)