fix(tests): test_849 savepoint-count 2→3 на лот (регресс #1921, main красный) #1923
1 changed files with 18 additions and 10 deletions
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue