Merge pull request #56622 from mihir-kandoi/pg-savepoint-txn-abort

fix: savepoint catch-and-continue DB writes to survive Postgres txn-abort (InFailedSqlTransaction)
This commit is contained in:
Mihir Kandoi
2026-06-29 22:11:47 +05:30
committed by GitHub
4 changed files with 8 additions and 1 deletions

View File

@@ -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") + "<br><br>" + str(e))
if notify:

View File

@@ -102,9 +102,11 @@ def create_routing(**args):
doc.update(args)
if not args.do_not_save:
frappe.db.savepoint("create_routing")
try:
doc.insert()
except frappe.DuplicateEntryError:
frappe.db.rollback(save_point="create_routing")
doc = frappe.get_doc("Routing", args.routing_name)
doc.delete_key("operations")
for operation in args.operations:

View File

@@ -779,6 +779,7 @@ def make_reposting_for_accounting_ledgers(transactions, company, repost_doc):
if reposting_map.get((voucher_type, voucher_no)):
continue
frappe.db.savepoint("repost_accounting_ledger")
try:
new_repost_doc = frappe.new_doc("Repost Item Valuation")
new_repost_doc.company = company
@@ -789,7 +790,7 @@ def make_reposting_for_accounting_ledgers(transactions, company, repost_doc):
new_repost_doc.flags.ignore_permissions = True
new_repost_doc.submit()
except Exception:
pass
frappe.db.rollback(save_point="repost_accounting_ledger")
def get_existing_reposting_only_gl_entries(reposting_reference):

View File

@@ -125,9 +125,11 @@ def make_purchase_receipt(
target_doc.save()
if submit and frappe.has_permission(target_doc.doctype, "submit", target_doc):
frappe.db.savepoint("submit_subcontracting_receipt")
try:
target_doc.submit()
except Exception as e:
frappe.db.rollback(save_point="submit_subcontracting_receipt")
target_doc.add_comment("Comment", _("Submit Action Failed") + "<br><br>" + str(e))
if notify: