From b6165844ed1314fbe40370fd3a2ae8cf9ab74986 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Mon, 29 Jun 2026 20:39:23 +0530 Subject: [PATCH] fix(buying): savepoint Subcontracting Order submit in make_subcontracting_order (Postgres) target_doc.submit() is wrapped in except Exception whose handler calls add_comment (a Comment insert). On Postgres a failed submit poisons the transaction so the add_comment insert raises InFailedSqlTransaction; MariaDB logs the comment. Savepoint + rollback before add_comment. No-op on MariaDB. --- erpnext/buying/doctype/purchase_order/mapper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/buying/doctype/purchase_order/mapper.py b/erpnext/buying/doctype/purchase_order/mapper.py index 468ab3e2e5d..1aa3d2c6eac 100644 --- a/erpnext/buying/doctype/purchase_order/mapper.py +++ b/erpnext/buying/doctype/purchase_order/mapper.py @@ -232,9 +232,11 @@ def make_subcontracting_order( target_doc.save() if submit and frappe.has_permission(target_doc.doctype, "submit", target_doc): + frappe.db.savepoint("submit_subcontracting_order") try: target_doc.submit() except Exception as e: + frappe.db.rollback(save_point="submit_subcontracting_order") target_doc.add_comment("Comment", _("Submit Action Failed") + "

" + str(e)) if notify: