From 9890a4189c271583b0c2e50ba13e4a14351ac291 Mon Sep 17 00:00:00 2001 From: bot-backend Date: Fri, 26 Jun 2026 19:29:08 +0300 Subject: [PATCH] =?UTF-8?q?fix(tests):=20test=5F849=20savepoint-count=202?= =?UTF-8?q?=E2=86=923=20=D0=BD=D0=B0=20=D0=BB=D0=BE=D1=82=20(#1921=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20upsert-reconcile?= =?UTF-8?q?=20SAVEPOINT,=20sequential)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/test_849_matching_savepoint.py | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 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..b2d7fab5 100644 --- a/tradein-mvp/backend/tests/test_849_matching_savepoint.py +++ b/tradein-mvp/backend/tests/test_849_matching_savepoint.py @@ -300,22 +300,30 @@ class TestSingleSavepointBatchIsolation: def test_no_begin_nested_inside_link_listing_to_house(self): """Verify that _link_listing_to_house does NOT open its own begin_nested. - The outer per-row SAVEPOINT (one call per lot in save_listings) is the only - SAVEPOINT level allowed. If begin_nested is called more than N lots times, - that indicates a double-nesting. + As of #1921, save_listings opens exactly 3 sequential (non-nested) SAVEPOINTs + per lot, all at the same level: + 1. upsert-reconcile SAVEPOINT (base.py ~line 500) — isolates INSERT so a + UniqueViolation on (source, source_id) can be caught and reconciled via + a plain UPDATE without aborting the whole session. + 2. snapshot SAVEPOINT (base.py ~line 621) — fault-tolerant snapshot write. + 3. hook SAVEPOINT (base.py ~line 645) — fault-tolerant house-matching hook. + + All three are sequential: each opens only after the previous has already + committed or rolled back. None is nested inside another. + + If _link_listing_to_house were to open its own inner begin_nested the count + would exceed 3 * len(lots) — that would indicate illegal double-nesting. """ db = _mock_save_db(inserted=True, listing_id=77) lots = [_base_lot(source_id=str(i)) for i in range(3)] 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), " + # 3 sequential SAVEPOINTs per lot (upsert-reconcile + snapshot + hook). + # > 3 * len(lots) would mean an inner SAVEPOINT was opened inside one of them. + assert db.begin_nested.call_count == 3 * len(lots), ( + f"Expected exactly 3 begin_nested per lot " + f"(upsert-reconcile + snapshot + hook, all sequential), " f"got {db.begin_nested.call_count} — inner SAVEPOINT may still be present" ) -- 2.45.3