Fix null issue when parsing search request attributes#2312
Merged
abhinavdangeti merged 11 commits intomasterfrom Apr 15, 2026
Merged
Fix null issue when parsing search request attributes#2312abhinavdangeti merged 11 commits intomasterfrom
null issue when parsing search request attributes#2312abhinavdangeti merged 11 commits intomasterfrom
Conversation
null issue when parsing search request objectsnull issue when parsing search request attributes
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses an edge case in SearchRequest JSON parsing where attributes stored as json.RawMessage can retain the literal bytes "null" after decoding, causing downstream len(...) > 0 checks to behave as if the attribute is present. It introduces a custom raw-message wrapper to treat JSON null as an unset/nil value during unmarshalling.
Changes:
- Introduce
OptionalRawMessageto decode JSONnull(and empty) into nil, preventing"null"payloads from being treated as present. - Update
SearchRequest.UnmarshalJSON(vectors + non-vectors) to useOptionalRawMessageforparamsandpre_search_data, and similarly for KNNparams/filter. - Add a vectors-mode regression test covering
knn[].params: nullandknn[].filter: null, including a marshal/unmarshal round-trip.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| search.go | Adds OptionalRawMessage wrapper type for json.RawMessage-like decoding with special null handling. |
| search_knn.go | Uses OptionalRawMessage in vectors-mode SearchRequest parsing for KNN/raw attributes; also adjusts JSON tags. |
| search_no_knn.go | Uses OptionalRawMessage in non-vectors SearchRequest parsing for raw attributes; also adjusts JSON tags. |
| search_knn_test.go | Adds vectors-mode test coverage for KNN null params/filter (and round-trip behavior). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
abhinavdangeti
approved these changes
Apr 14, 2026
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.
json.RawMessagelikeKNN ParamsKNN FilterPresearchDatanullfor these attributes, especially after a marshal-unmarshal cycle.nullvalue is passed on downstream, causing every check forlen(attribute) > 0to succeed and take the path for which the attribute is valid even if the attribute is actuallynil.nullspecially and sets the attribute tonilwhen required.