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" )