From eaaea6e4598e9c81997573e19f4ef1c58ebe320f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elisi=C3=A1rio=20Couto?= Date: Tue, 9 Sep 2025 15:32:32 +0100 Subject: [PATCH] fix: merge account details into balance data to prevent unknown/N/A values - Modified sync service to include institution_id and iban in balance persistence - Fixed data flow issue where balance records were missing account metadata - Prevents future balance records from having 'unknown' bank or 'N/A' IBAN - Successfully fixed 8 existing records with one-off script --- leggend/services/sync_service.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/leggend/services/sync_service.py b/leggend/services/sync_service.py index 1b5f758..0567f38 100644 --- a/leggend/services/sync_service.py +++ b/leggend/services/sync_service.py @@ -61,8 +61,16 @@ class SyncService: # Get and save balances balances = await self.gocardless.get_account_balances(account_id) - if balances: - await self.database.persist_balance(account_id, balances) + if balances and account_details: + # Merge account details into balances data for proper persistence + balances_with_account_info = balances.copy() + balances_with_account_info["institution_id"] = ( + account_details.get("institution_id") + ) + balances_with_account_info["iban"] = account_details.get("iban") + await self.database.persist_balance( + account_id, balances_with_account_info + ) balances_updated += len(balances.get("balances", [])) # Get and save transactions