mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 06:31:48 +00:00
fix(crm): scope create_address rollback to a savepoint (review)
create_address is a helper called by create_prospect/create_customer AFTER they insert the Prospect/Customer. Its full frappe.db.rollback() on an address-save failure rolled back the caller's just-inserted parent doc, then swallowed the exception, so the caller returned a Prospect/Customer name that no longer existed. Scope the rollback to savepoint('crm_create_address') so only the address work is undone; the parent doc survives and the failed address is just logged.
This commit is contained in:
@@ -71,6 +71,7 @@ def create_address(doctype, docname, address):
|
||||
if not address:
|
||||
return
|
||||
address = frappe.parse_json(address)
|
||||
frappe.db.savepoint("crm_create_address")
|
||||
try:
|
||||
_address = frappe.db.exists("Address", address.get("name"))
|
||||
if not _address:
|
||||
@@ -98,7 +99,7 @@ def create_address(doctype, docname, address):
|
||||
address.save(ignore_permissions=True)
|
||||
return address.name
|
||||
except Exception:
|
||||
frappe.db.rollback()
|
||||
frappe.db.rollback(save_point="crm_create_address")
|
||||
frappe.log_error(frappe.get_traceback(), f"Error while creating address for {docname}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user