Skip to content

A local-first personal finance app

Fix crash when deleting child transactions from an errored split (#4465)

Julian Dominguez-Schatz398ada0afd37
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx b/packages/desktop-client/src/components/transactions/TransactionsTable.jsx
index 79dc8a70e6..8312f63b68 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.jsx
@@ -1861,6 +1861,7 @@ function TransactionTableInner({
: trans.error;
const hasSplitError =
+ (trans.is_parent || trans.is_child) &&
(!expanded || isLastChild(transactions, index)) &&
error &&
error.type === 'SplitTransactionError';
diff --git a/packages/loot-core/src/shared/transactions.test.ts b/packages/loot-core/src/shared/transactions.test.ts
index 7b0c696972..e083bcb126 100644
--- a/packages/loot-core/src/shared/transactions.test.ts
+++ b/packages/loot-core/src/shared/transactions.test.ts
@@ -206,4 +206,23 @@ describe('Transactions', () => {
expect.objectContaining({ amount: 3002 }),
]);
});
+
+ test('deleting all child split transactions works', () => {
+ const transactions = [
+ makeTransaction({ amount: 2001 }),
+ ...makeSplitTransaction(
+ { id: 't1', amount: 2500, error: splitError(500) },
+ [{ id: 't2', amount: 2000 }],
+ ),
+ makeTransaction({ amount: 3002 }),
+ ];
+ const { data } = deleteTransaction(transactions, 't2');
+
+ expect(data).toEqual([
+ expect.objectContaining({ amount: 2001 }),
+ // Must delete error if no children
+ expect.objectContaining({ amount: 2500, error: null }),
+ expect.objectContaining({ amount: 3002 }),
+ ]);
+ });
});
diff --git a/packages/loot-core/src/shared/transactions.ts b/packages/loot-core/src/shared/transactions.ts
index 6142640bce..afd3b7229c 100644
--- a/packages/loot-core/src/shared/transactions.ts
+++ b/packages/loot-core/src/shared/transactions.ts
@@ -282,10 +282,11 @@ export function deleteTransaction(
if (trans.id === id) {
return null;
} else if (trans.subtransactions?.length === 1) {
- const { error, subtransactions, ...rest } = trans;
+ const { subtransactions, ...rest } = trans;
return {
...rest,
is_parent: false,
+ error: null,
} satisfies TransactionEntity;
} else {
const sub = trans.subtransactions?.filter(t => t.id !== id);
diff --git a/upcoming-release-notes/4465.md b/upcoming-release-notes/4465.md
new file mode 100644
index 0000000000..869cc6b2e3
--- /dev/null
+++ b/upcoming-release-notes/4465.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [jfdoming]
+---
+
+Fix crash when deleting child transactions from an errored split