fix(integrations): savepoint the Plaid bank-account update branch + rollback add_institution (Postgres)

add_bank_accounts hardened only the INSERT branch with savepoint('plaid_bank_account'); the parallel else/UPDATE branch ran log_error+throw after a failed existing_account.save() with no rollback -> InFailedSqlTransaction on Postgres (masking the friendly throw). Mirror the insert branch with savepoint('plaid_update_account')+rollback. Also add_institution's except log_error after a failed bank.insert() now rolls back first. No-op on MariaDB.
This commit is contained in:
Mihir Kandoi
2026-06-29 22:42:47 +05:30
parent 298df4d3aa
commit 09a3eb8509

View File

@@ -69,6 +69,7 @@ def add_institution(token: str, response: str | dict):
)
bank.insert()
except Exception:
frappe.db.rollback()
frappe.log_error("Plaid Link Error")
else:
bank = frappe.get_doc("Bank", response["institution"]["name"])
@@ -154,6 +155,7 @@ def add_bank_accounts(response: str | dict, bank: str | dict, company: str):
)
else:
frappe.db.savepoint("plaid_update_account")
try:
existing_account = frappe.get_doc("Bank Account", existing_bank_account)
existing_account.update(
@@ -169,6 +171,7 @@ def add_bank_accounts(response: str | dict, bank: str | dict, company: str):
existing_account.save()
result.append(existing_bank_account)
except Exception:
frappe.db.rollback(save_point="plaid_update_account")
frappe.log_error("Plaid Link Error")
frappe.throw(
_("There was an error updating Bank Account {0} while linking with Plaid.").format(