fix(stock): fall back gracefully when transaction_advisory_lock is unavailable

Same hasattr pattern as repost_gate: an ERPNext ahead of its frappe build keeps
the status-quo serialization-failure retries instead of failing every stock
submission on postgres.
This commit is contained in:
Mihir Kandoi
2026-07-16 09:32:03 +05:30
parent 35a9d7b09c
commit 897eca895a

View File

@@ -294,8 +294,10 @@ def sle_processing_gate(item_code, warehouse):
gap locks its previous-SLE locking reads take (which also block, then reveal, concurrent
inserts); postgres locking reads never see rows another transaction is inserting, so without
this gate two concurrent writers compute from the same stale previous SLE and the loser's Bin
write is lost. Txn-scoped and re-entrant; released at commit/rollback."""
if frappe.db.db_type == "postgres":
write is lost. Txn-scoped and re-entrant; released at commit/rollback. hasattr keeps a frappe
predating transaction_advisory_lock on the status quo (serialization-failure retries) instead
of breaking every stock submission."""
if frappe.db.db_type == "postgres" and hasattr(frappe.db, "transaction_advisory_lock"):
frappe.db.transaction_advisory_lock(("stock-sle", item_code, warehouse), timeout=REPOST_LOCK_TIMEOUT)