diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py index 25d5a861a4b..bcab065bba4 100644 --- a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py +++ b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py @@ -215,7 +215,14 @@ def sync_transactions(bank, bank_account): result = [] if transactions: for transaction in reversed(transactions): - result += new_bank_transaction(transaction) + # per-transaction savepoint: a failed insert/submit must not discard the Bank + # Transactions already synced this run (MariaDB keeps them) nor poison the txn on Postgres + frappe.db.savepoint("plaid_sync_txn") + try: + result += new_bank_transaction(transaction) + except Exception: + frappe.db.rollback(save_point="plaid_sync_txn") + raise if result: last_transaction_date = frappe.db.get_value("Bank Transaction", result.pop(), "date")