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"]