Repository navigation
fix: queryMany returns [] instead of [[]] for a single query with zero matches - #70
Merged
CahidArda merged 2 commits intoNov 19, 2026
Merged
Conversation
…o matches QueryManyCommand.exec() normalizes the API's flat single-query response into the documented QueryResult[][] shape by checking `result.length > 0 && !Array.isArray(result[0])`. When the single query has zero matches, the API returns [] (a flat empty array), so `result.length > 0` is false and the wrapping branch is skipped entirely - the method returns [] instead of [[]], breaking the type contract and making `results[0]` undefined instead of an empty array for a caller reading the first query's matches. This is exactly the case PR upstash#66 (fixing upstash#38) was written to handle, just missed at the empty-array boundary: `result[0]` is already `undefined` (not an array) when result is empty, so `!Array.isArray(result[0])` alone is sufficient - the `result.length > 0` guard was unnecessary and excluded the one case that needed it most. Added index.unit.test.ts with a mocked Requester to cover this directly, including a check that the added test fails without the fix and passes with it. The existing index.test.ts integration tests need a live index and can't cheaply construct a guaranteed-zero-match single query, which is why this is a separate mocked unit test rather than an addition there.
CahidArda
previously approved these changes
Nov 19, 2026
…xed batches When the namespace does not exist the API answers with a single empty array for any number of queries, so queryMany returned [] instead of one empty array per query. Fill the result to the number of queries. Data queries and vector queries are served by different endpoints. A batch with both was sent to the data endpoint and failed there; fail early with a clear error instead. A data query with an empty string is now routed as a data query.
CahidArda
approved these changes
Nov 19, 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.
Summary
QueryManyCommand.exec()normalizes the API's flat single-query response into the documentedQueryResult[][]shape, but the normalization is skipped when the single query has zero matches - returning[]instead of[[]].Root cause
This is exactly the case #66 (fixing #38) was written to handle: a single query sent via
queryMany()gets a flat array back from the API instead of a nested one, and this code wraps it. But when that single query matches nothing, the API returns[](a flat empty array) -result.length > 0isfalse, the wrapping branch is skipped, and the method returns[]instead of[[]]. This breaks theQueryResult<TMetadata>[][]return type contract for exactly the case the fix exists for, and a caller doingresults[0]to read the first (only) query's matches getsundefinedinstead of[].result[0]is alreadyundefined(not an array) whenresultis empty, so!Array.isArray(result[0])alone is sufficient to detect the flat shape - theresult.length > 0guard was unnecessary, and it happened to exclude the one case that needed the wrap most.Fix
Drop the
result.length > 0guard;!Array.isArray(result[0])already correctly identifies the flat shape in both the non-empty and empty cases.Tests
index.test.ts's existing coverage is integration-style (a real Upstash Vector index via live credentials), which can't cheaply construct a guaranteed-zero-match single query. Addedindex.unit.test.tswith a mockedRequesterto test the normalization logic directly:[[]](the bug this PR fixes)[[], []]) -> passed through unchangedVerified the new zero-match test actually catches the bug: reverted the fix locally and confirmed that test fails (
expected [[]], received []) while the other three still pass; restored the fix and all four pass.Test plan
bun test src/commands/client/query/query-many/index.unit.test.ts- 4/4 passingbun run lint- no new errors introduced (pre-existing unrelated errors inexamples/nextjsandtest-utils.tsconfirmed present onmainbefore this change too)prettier --checkcleantsupbuild succeeds