fix(stock): savepoint per-company Material Request creation in reorder (Postgres)

create_material_request loops companies inserting+submitting a Material Request; the except calls mr.log_error (INSERT) with no rollback, raising InFailedSqlTransaction on Postgres in the scheduled reorder job, and the next company runs in the poisoned txn. Savepoint per iteration + rollback(save_point=) before log_error. No-op on MariaDB.
This commit is contained in:
Mihir Kandoi
2026-06-29 22:38:02 +05:30
parent c97eac34bf
commit 298df4d3aa

View File

@@ -216,6 +216,7 @@ def create_material_request(material_requests):
company_wise_mr = frappe._dict({})
for request_type in material_requests:
for company in material_requests[request_type]:
frappe.db.savepoint("reorder_mr")
try:
items = material_requests[request_type][company]
if not items:
@@ -287,6 +288,7 @@ def create_material_request(material_requests):
company_wise_mr.setdefault(company, []).append(mr)
except Exception as exception:
frappe.db.rollback(save_point="reorder_mr")
exceptions_list.append(exception)
mr.log_error("Unable to create material request")