Skip to content

fix(ffapi): preserve big number values in QueryBuilder filters - #256

Draft
EnriqueL8 wants to merge 1 commit into
mainfrom
fix-query-builder-bigint
Draft

EnriqueL8 wants to merge 1 commit into
mainfrom
fix-query-builder-bigint

Conversation

@EnriqueL8

Copy link
Copy Markdown
Contributor

Problem

toSimpleValue in pkg/ffapi/restfilter_json_builder.go converts every non-string value via fftypes.JSONObject{"v": v}.GetString("v"). GetStringOk only understands string, bool, floats and the built-in int/uint types, so *big.Int, *fftypes.FFBigInt and json.Number fall through to its default case, which logs Invalid string value '…' for key 'v' and returns "".

The result is that Equal, NotEqual, GreaterThan, …, In and NotIn silently build a filter with an empty value. Because value is omitempty, the serialized query is {"eq":[{"field":"amount"}]}, so a remote API receives a filter with no value at all. This happens even for small values (big.NewInt(42)), so the problem is the type, not the size.

Fix

Handle json.Number, *big.Int and *fftypes.FFBigInt explicitly in toSimpleValue, rendering the full decimal string. Nil pointers map to "" (unchanged behaviour). Everything else still goes through the existing GetString fallback.

Tests

TestQueryBuilderValueTypes covers single-value ops, multi-value ops and the serialized JSON for string/int/uint64/bool (controls) plus *big.Int (small and uint256 max), *fftypes.FFBigInt and json.Number. Before this change, the four big-number cases failed with actual: "". They now pass.

🤖 Generated with Claude Code

toSimpleValue fell back to JSONObject.GetString for any non-string value,
which only handles string/bool/float/int/uint. *big.Int, *fftypes.FFBigInt
and json.Number hit its default case, logged an error and returned "", so
the filter was silently built with an empty value (dropped entirely from
the serialized JSON due to omitempty).

Handle these types explicitly, rendering their full decimal string.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Enrique Lacal <enrique.lacal@kaleido.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant