From 731f5538a5b60c64c3e413e2e2a85f1f2c6cd92a Mon Sep 17 00:00:00 2001 From: Light1YT Date: Fri, 26 Jun 2026 22:22:32 +0500 Subject: [PATCH] fix(test): test_849 expects 3 begin_nested/lot after upsert-reconcile SAVEPOINT (#1921) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../tests/test_849_matching_savepoint.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tradein-mvp/backend/tests/test_849_matching_savepoint.py b/tradein-mvp/backend/tests/test_849_matching_savepoint.py index 297ae453..b67ae4f4 100644 --- a/tradein-mvp/backend/tests/test_849_matching_savepoint.py +++ b/tradein-mvp/backend/tests/test_849_matching_savepoint.py @@ -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" )