fix(database): include meta_data in GetBalanceByIDLite - #351
Open
vjymisal0 wants to merge 2 commits into
Open
Conversation
GetBalanceByIDLite's SELECT omitted meta_data, so every balance it returned had MetaData == nil regardless of what was stored. This function backs the source/destination lookups in getSourceAndDestination (transaction_execution.go), whose result is passed straight to the Typesense index batch in postTransactionActions. The nil MetaData overwrites the balance's real metadata in the search index on every transaction, even though the row in Postgres is untouched. Add meta_data to the query and scan/unmarshal it into balance.MetaData, following the same nil-safe pattern already used in GetSourceDestination and GetAllBalances. GetBalancesByIDsLite (the bulk sibling of this function, used by transaction_coalescing.go and lineage_allocation.go) has the same gap and is a good candidate for a follow-up fix, but is out of scope here since issue blnkfinance#256 is specifically about the single-balance lookup path. Fixes blnkfinance#256
Collaborator
|
Hi @vjymisal0, thanks for the PR. There are some failing tests. Could you please look into them? |
…anceByIDLite The previous commit added meta_data as a 16th column to the GetBalanceByIDLite query/Scan, and updated database/balance_test.go's mocks accordingly, but missed the sqlmock expectations in the top-level account_test.go and transaction_test.go, which still supplied 15 columns. This caused CI's test and race jobs to fail with "sql: expected 15 destination arguments in Scan, not 16". Add "meta_data" to every affected NewRows()/AddRow() pair and to the balanceQuery regex literals in transaction_test.go so they match the 16-column query GetBalanceByIDLite now issues.
vjymisal0
force-pushed
the
fix/balance-lite-missing-metadata
branch
from
August 15, 2026 02:59
ba26db3 to
b9c9e47
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
GetBalanceByIDLite(database/balance.go) selectsbalance_id, indicator, currency, ledger_id, balance, credit_balance, debit_balance, inflight_balance, inflight_credit_balance, inflight_debit_balance, created_at, version, track_fund_lineage, allocation_strategy, identity_id—meta_datais not in the list, so every*model.Balanceit returns hasMetaData == nil, no matter what's stored in Postgres.This function is the default path in
getSourceAndDestination(transaction_execution.go) used to look up the source/destination balance for a transaction whenEnableQueuedChecksis off.postTransactionActionsthen hands that balance straight tosearch.NewIndexBatch/batch.AddDependency("balances", ...), which re-upserts it into Typesense. BecauseMetaDatais nil on the struct (not because it was actually cleared in the DB), the balance's real metadata gets wiped from the search index on every transaction touching that balance.Repro from the issue:
meta_data./search/balances.meta_datais now empty, even thoughSELECT meta_data FROM blnk.balances WHERE balance_id = ...still shows it in Postgres.Fix
Add
meta_datato the SELECT and scan it into a[]byte, then unmarshal intobalance.MetaDatawhen non-empty — the same nil-safe pattern already used byGetSourceDestinationandGetAllBalanceselsewhere in this file, so this bringsGetBalanceByIDLitein line with its siblings rather than introducing a new pattern.Scope note
GetBalancesByIDsLite(the bulk version, used bytransaction_coalescing.goandlineage_allocation.go) has the identical gap — its SELECT also omitsmeta_data. I left it untouched since issue #256 is specifically about the single-lookup path and I wanted to keep this PR focused; happy to open a follow-up for the bulk path if useful.Testing
GetBalanceByIDLitesqlmock tests for the new query text/columns.TestGetBalanceByIDLite_Successassertion thatmeta_dataround-trips (was previously not asserted at all, which is how this shipped).TestGetBalanceByIDLite_NilMetaDatafor the NULLmeta_datacase.go test ./database/...passes (three env-dependent_RealDBtests skip locally, no Postgres running — unrelated to this change).go vet ./...andgolangci-lint run ./database/...are clean on the changed files (one pre-existing, unrelated staticcheck note elsewhere inbalance.goat line ~1455, outside this diff).gofmtclean.Fixes #256