fix: validate local query parameters - #1339
Conversation
✅ Deploy Preview for poetic-froyo-8baba7 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe local synchronous and asynchronous clients now validate nested prefetch limits, matrix-search limits and samples, query offsets, and grouped-query sizes. Validation occurs before query processing. In-memory and asynchronous tests cover invalid parameters and expected Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The PR adds localized validation for invalid local query and matrix parameters while preserving valid requests; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
shashvat-singham
left a comment
There was a problem hiding this comment.
Ran the branch — tests/test_in_memory.py is 12 passed, and I couldn't find a hole in the coverage.
Since the whole point here is matching server behaviour, I cross-checked each new bound against the validation attributes in lib/api/src/rest/schema.rs rather than assuming:
| check | this PR | qdrant core |
|---|---|---|
limit |
< 1 |
#[validate(range(min = 1))] |
sample |
< 2 |
#[validate(range(min = 2))] |
group_size |
< 1 |
#[validate(range(min = 1))] |
prefetch limit |
< 1 |
#[validate(range(min = 1))] |
offset |
< 0 |
Option<usize> |
All five line up. sample < 2 was the one I expected to be off — it's the only non-obvious constant — but core really does require min = 2, so it's right.
I also probed for paths the recursion might miss, and they're all covered:
batch: offset=-1 -> ValueError
batch: prefetch limit=0 -> ValueError
groups: prefetch limit=0 -> ValueError
nested prefetch limit=0 -> ValueError # prefetch(limit=5, prefetch=prefetch(limit=0))
scroll(limit=0) -> ValueError
The recursive _validate_prefetch_limits handling both the single-Prefetch and list[Prefetch] shapes is what makes the nested and batch cases work, and it's easy to get that wrong given prefetch is overloaded that way in the models.
One deliberate behaviour change worth calling out in the description: validation now runs before _get_collection, so query_points("missing", offset=-1) raises ValueError: offset value -1 is invalid where it previously raised collection-not-found. The tests encode that by using "missing" as the collection name. I think it's correct — the server validates the request body before it looks the collection up, so a 400 beats a 404 there, and it matches where the pre-existing limit < 1 check already sat — but it is a visible change for anyone catching the old error, so it's worth being explicit rather than leaving it implied by the test fixtures.
Nothing blocking from me.
All Submissions:
devbranch. Did you create your branch fromdev?Changes to Core Features:
Problem
Local mode accepted several invalid query bounds that the server rejects:
The server schemas define Query API
offset >= 0andlimit >= 1, grouped-querygroup_size >= 1, and matrixlimit >= 1/sample >= 2. See the Query points, Query point groups, and Distance matrix offsets references.This follows the local/server validation parity work in #1280 and #1281, which covered top-level positive limits but not these remaining bounds.
Fix
Valid requests are unchanged. Invalid local requests now fail early with
ValueErrorinstead of returning misleading results.Impact (X-Y-Z)
Validation
9 passed)12 passed)22 passed,99%coverage)mypy,pyright, local collection doctest, Ruff, and all pre-commit hooks