Skip to content

Balance history endpoint returns false "No Balance Data at Date" due to sub-second precision mismatch #1955

@gandalf-at-lerian

Description

@gandalf-at-lerian

The GET .../balances/:balance_id/history?date= endpoint returns error 0141 - No Balance Data at Date when querying a balance at a timestamp within the same second it was created.

Root cause: In components/transaction/internal/services/query/get-balance-at-timestamp.go:63, the comparison currentBalance.CreatedAt.After(timestamp) uses the database's sub-second precision (created_at = 23:15:15.500Z) against the API's second-precision parsed input (timestamp = 23:15:15.000Z). When the balance was created in the same second as the query timestamp but with a higher fractional component, the check incorrectly concludes the balance didn't exist yet.

Reproduction: Create a balance and immediately query its history at time.Now() truncated to seconds — the request intermittently fails depending on sub-second timing.

Suggested fix: Truncate both sides of the comparison to second precision, matching the API's input granularity:

if currentBalance.CreatedAt.Truncate(time.Second).After(timestamp.Truncate(time.Second)) {

The same pattern should be checked in GetAccountBalancesAtTimestamp if it has an equivalent comparison.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions