From d255d7ddc9a52971e288c4b41dd621fed79d769f Mon Sep 17 00:00:00 2001 From: padreug Date: Tue, 11 Nov 2025 02:53:41 +0100 Subject: [PATCH] Fix virtual parent detection by refreshing account list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: Virtual intermediate parents weren't being created because all_account_names was built from stale data (before Step 1 synced new accounts). Example failure: - Beancount has: Expenses:Supplies:Food, Expenses:Supplies:Kitchen - Step 1 syncs these to Castle DB - Step 3 checks if parent 'Expenses:Supplies' exists - But checks against OLD account list (before Step 1) - Doesn't find the children, so can't detect missing parent Fix: Re-fetch accounts from database after Step 1 completes, so all_account_names includes newly synced children. 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude --- account_sync.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/account_sync.py b/account_sync.py index b5d277f..95fe41c 100644 --- a/account_sync.py +++ b/account_sync.py @@ -233,7 +233,11 @@ async def sync_accounts_from_beancount(force_full_sync: bool = False) -> dict: # Step 3: Auto-generate virtual intermediate parent accounts # For each account in Beancount, check if all parent levels exist # If not, create them as virtual accounts - all_account_names = set(castle_accounts_by_name.keys()) + + # IMPORTANT: Re-fetch accounts from DB after Step 1 added new accounts + # Otherwise we'll be checking against stale data and miss newly synced children + current_castle_accounts = await get_all_accounts(include_inactive=True) + all_account_names = {acc.name for acc in current_castle_accounts} for bc_account in beancount_accounts: account_name = bc_account["account"]