Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
9890a4189c fix(tests): test_849 savepoint-count 2→3 на лот (#1921 добавил upsert-reconcile SAVEPOINT, sequential)
All checks were successful
CI / changes (pull_request) Successful in 7s
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped
2026-06-26 19:29:08 +03:00

View file

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