Compare commits
1 commit
main
...
fix/test-8
| Author | SHA1 | Date | |
|---|---|---|---|
| 9890a4189c |
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):
|
def test_no_begin_nested_inside_link_listing_to_house(self):
|
||||||
"""Verify that _link_listing_to_house does NOT open its own begin_nested.
|
"""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
|
As of #1921, save_listings opens exactly 3 sequential (non-nested) SAVEPOINTs
|
||||||
SAVEPOINT level allowed. If begin_nested is called more than N lots times,
|
per lot, all at the same level:
|
||||||
that indicates a double-nesting.
|
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)
|
db = _mock_save_db(inserted=True, listing_id=77)
|
||||||
lots = [_base_lot(source_id=str(i)) for i in range(3)]
|
lots = [_base_lot(source_id=str(i)) for i in range(3)]
|
||||||
|
|
||||||
save_listings(db, lots)
|
save_listings(db, lots)
|
||||||
|
|
||||||
# save_listings calls begin_nested once per lot for the snapshot
|
# 3 sequential SAVEPOINTs per lot (upsert-reconcile + snapshot + hook).
|
||||||
# and once per lot for the hook — so 2 * len(lots) total.
|
# > 3 * len(lots) would mean an inner SAVEPOINT was opened inside one of them.
|
||||||
# If _link_listing_to_house opens an INNER begin_nested too,
|
assert db.begin_nested.call_count == 3 * len(lots), (
|
||||||
# the count would be > 2 * len(lots).
|
f"Expected exactly 3 begin_nested per lot "
|
||||||
# (snapshot SAVEPOINT + hook SAVEPOINT = 2 per lot, no extra inner)
|
f"(upsert-reconcile + snapshot + hook, all sequential), "
|
||||||
assert db.begin_nested.call_count == 2 * len(lots), (
|
|
||||||
f"Expected exactly 2 begin_nested per lot (snapshot + hook outer), "
|
|
||||||
f"got {db.begin_nested.call_count} — inner SAVEPOINT may still be present"
|
f"got {db.begin_nested.call_count} — inner SAVEPOINT may still be present"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue