mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-19 03:17:55 +00:00
fix(accounts): savepoint per-row merge in Ledger Merge (Postgres)
start_merge merges accounts in a loop; on failure it only rolled back when not in_test, so in tests a failed merge_account left the Postgres txn poisoned and the except log_error + the finally db_set(status) raised InFailedSqlTransaction. Wrap each row in savepoint('ledger_merge_row') and rollback to it unconditionally before log_error - this recovers the txn in both paths without the full rollback discarding the rest of the test transaction. Production still commits per successful merge, so the per-iteration savepoint rollback is equivalent to the prior full rollback. No-op on MariaDB.
This commit is contained in:
@@ -65,6 +65,7 @@ def start_merge(docname):
|
|||||||
total = len(ledger_merge.merge_accounts)
|
total = len(ledger_merge.merge_accounts)
|
||||||
for row in ledger_merge.merge_accounts:
|
for row in ledger_merge.merge_accounts:
|
||||||
if not row.merged:
|
if not row.merged:
|
||||||
|
frappe.db.savepoint("ledger_merge_row")
|
||||||
try:
|
try:
|
||||||
merge_account(
|
merge_account(
|
||||||
row.account,
|
row.account,
|
||||||
@@ -79,8 +80,7 @@ def start_merge(docname):
|
|||||||
{"ledger_merge": ledger_merge.name, "current": successful_merges, "total": total},
|
{"ledger_merge": ledger_merge.name, "current": successful_merges, "total": total},
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
if not frappe.in_test:
|
frappe.db.rollback(save_point="ledger_merge_row")
|
||||||
frappe.db.rollback()
|
|
||||||
ledger_merge.log_error("Ledger merge failed")
|
ledger_merge.log_error("Ledger merge failed")
|
||||||
finally:
|
finally:
|
||||||
if successful_merges == total:
|
if successful_merges == total:
|
||||||
|
|||||||
Reference in New Issue
Block a user