Skip to content

Commit 8edcb68

Browse files
Tom Maloneyclaude
andcommitted
fix: Use try-finally to ensure temp backend cleanup
Refactor YNAB budget selection to use try-finally block, guaranteeing temp_backend.clear_auth() is called even if an unexpected exception occurs between login and the exception handler. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c5561f6 commit 8edcb68

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

moneyflow/app.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,16 +623,12 @@ async def _handle_add_new_account(self, account_manager: AccountManager):
623623

624624
if budget_id is None:
625625
# User cancelled budget selection - clean up
626-
temp_backend.clear_auth()
627626
creds.clear()
628627
account_manager.delete_account(account.id)
629628
return None
630629
elif len(budgets) == 1:
631630
budget_id = budgets[0]["id"]
632631

633-
# Clear the temporary backend
634-
temp_backend.clear_auth()
635-
636632
# Update the account with the selected budget_id
637633
if budget_id:
638634
account.budget_id = budget_id
@@ -648,10 +644,12 @@ async def _handle_add_new_account(self, account_manager: AccountManager):
648644
logger = get_logger(__name__)
649645
logger.error("Failed to fetch YNAB budgets during account setup")
650646
# Clean up credentials and account if budget selection fails
651-
temp_backend.clear_auth()
652647
creds.clear()
653648
account_manager.delete_account(account.id)
654649
return None
650+
finally:
651+
# Always clear temporary backend auth to minimize credential exposure
652+
temp_backend.clear_auth()
655653
else:
656654
# Backend doesn't need credentials (Amazon, Demo)
657655
creds = {"backend_type": backend_type}

0 commit comments

Comments
 (0)