From 298df4d3aa7255bfb900f7ce60d2a794fbf071b0 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Mon, 29 Jun 2026 22:38:02 +0530 Subject: [PATCH] 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. --- erpnext/stock/reorder_item.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py index 5c668fa8a8d..8955c7f46e6 100644 --- a/erpnext/stock/reorder_item.py +++ b/erpnext/stock/reorder_item.py @@ -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")