fix: validate is_in/not_in receive a list in the filter builder - #683
NishchayMahor wants to merge 1 commit into
Conversation
Field.is_in() and Field.not_in() accepted any value, so Field("genre").is_in("drama")
silently produced {"genre": {"$in": "drama"}} — an invalid filter the server
rejects with an opaque 400. This is inconsistent with gt/gte/lt/lte, which already
validate via _require_numeric. Add a matching _require_list guard (accepts list or
tuple) and call it from is_in/not_in, with unit tests mirroring the numeric ones.
47a999d to
9bc017a
Compare
|
Rebased onto current The conflict was real content overlap rather than drift:
Verification on the rebased branch: Force-pushed to rebase (old head |
What
In the metadata filter builder,
Field.is_in()/Field.not_in()accept any value without checking it's a list. A common mistake — passing a bare value instead of a list — is silently turned into an invalid filter:Because a string is iterable, nothing catches this client-side; the server rejects it later with an opaque
400 Invalid request, which is hard to trace back to the filter.This is inconsistent with the numeric operators in the same class —
gt/gte/lt/ltealready validate their argument via_require_numericand raise a clearTypeError.Fix
Add a
_require_listguard mirroring the existing_require_numeric, and call it fromis_in/not_in(pinecone/utils/filter_builder.py). It accepts alistortupleand raises a clearTypeErrorotherwise:Valid
list/tupleusage is unchanged.Testing
Added tests to
TestFieldSetOperatorsintests/unit/utils/test_filter_builder.py, mirroring the existingtest_numeric_only_*cases (tuple accepted;is_in/not_inwith a non-list raiseTypeErrormatching "list"). Verified the behavior directly against the module —filter_builder.pyis pure Python (list/tuple pass,str/intraise).Note
Low Risk
Pure client-side validation in the optional filter builder; no API or server behavior changes beyond catching mistakes earlier.
Overview
Field.is_in()andField.not_in()now validate their argument at build time via a new_require_listhelper (same idea as_require_numericon comparison operators). Passing a bare scalar (e.g. a string) no longer silently produces an invalid$in/$ninfilter that fails later with a vague API error—it raises aTypeErrorwith a clear message.listandtupleinputs still work as before.Unit tests cover tuple acceptance and
TypeErrorfor non-list values on both operators.Reviewed by Cursor Bugbot for commit 9bc017a. Bugbot is set up for automated code reviews on this repo. Configure here.