Repository navigation
Conversation
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change aligning empty-iterator behavior across query and generate APIs.
No open issues 🎉
What changed in this PR
Makes fetch_objects_by_ids return empty results for empty iterators, matching empty-list behavior in both query and generate APIs.
Changes:
- Builds ID filters once, preserving single-pass consumption of non-empty iterators.
- Reuses the existing empty-response paths when no filters are produced.
- Adds offline regression tests for query and generate calls on synchronous and asynchronous clients.
| File | Description |
|---|---|
weaviate/collections/queries/fetch_objects_by_ids/query/executor.py |
Detects empty inputs from the constructed filters before querying. |
weaviate/collections/queries/fetch_objects_by_ids/generate/executor.py |
Applies the same empty-iterator handling to generation. |
test/collection/test_queries.py |
Adds four empty-iterator regression cases without connecting to a server. |
Review effort: Balanced
|
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge. |
Mansi2221
left a comment
There was a problem hiding this comment.
Right fix for the empty-iterator regression. The old if not ids check was ambiguous — it short-circuited for both an empty collection and for ids=None, but when ids was an iterator, if not ids on a generator object is always truthy regardless of whether it would yield anything, so the empty-iterator branch fell through to the error path that constructed Filter.any_of([]).
Materializing the iterator into id_filters once and then branching on not id_filters gives both:
- A single-pass consumption of the iterator (correct for generators)
- An unambiguous empty-list check
The symmetrical fix in both query/executor.py and generate/executor.py plus the sync+async parametrized tests covers the full API surface. One minor observation: the test uses a real WeaviateClient with a localhost:8080 connection — since the test expects to return an empty result without any gRPC round-trip, the short-circuit should fire before any network I/O. That's visible in the diff. Good.
LGTM.
When a caller filters a stream of IDs down to zero items,
fetch_objects_by_idsraisesWeaviateInvalidInputError: Filter.any_of must have at least one filter. Passing an empty list to the same method returns an empty result. Both inputs satisfy the advertisedIterableargument.The query and generate paths now build the ID filters once and return the existing empty response when there are none. A non-empty iterator is still consumed only once.
The regression tests call both APIs on synchronous and asynchronous clients without connecting to a server. All four failed on main and pass with this change. I also checked that a two-ID generator still sends both IDs, in order, in the gRPC request.
Local checks passed: 717 unit tests (one skipped), all 118 mock-server tests, Ruff, and Flake8.