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:
Mihir Kandoi
2026-06-30 13:01:32 +05:30
parent a36065931d
commit 460bb9e5d0

View File

@@ -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}")