Repository navigation
fix: raise FilterError for incomparable document values in range filters - #13618
Open
Harshil26202 wants to merge 1 commit into
Open
Harshil26202 wants to merge 1 commit into
Harshil26202 wants to merge 1 commit into
Conversation
A list or dict stored in the filtered field made >, >=, < and <= filters raise a raw TypeError from the comparison. Convert it to FilterError, which is what these operators already raise for other incomparable values.
Harshil26202
requested review from
bogdankostic
and removed request for
a team
November 7, 2026 18:32
Contributor
|
@Harshil26202 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
chrikrah
reviewed
Nov 8, 2026
chrikrah
left a comment
Contributor
There was a problem hiding this comment.
@Harshil26202 nothing blocks a merge. Reverting filters.py fails 8 tests:
# head 59bb7192, base 0ad74747, python 3.12, haystack imported from the exported head tree
$ PYTHONPATH=. python -m pytest test/utils/test_filters.py -q -p no:cacheprovider
# head
166 passed in 0.19s
# head with haystack/utils/filters.py reverted to base
8 failed, 158 passed in 0.26s
# Document(meta={"page": 3}), Document(meta={"page": [1, 2]}), filter meta.page > 1
# head: InMemoryDocumentStore.filter_documents and MetadataRouter.run both raise FilterError
# base: both raise TypeError: '>' not supported between instances of 'list' and 'int'
# filter side: {"field": "meta.page", "operator": ">", "value": {"a": 1}} on Document(meta={"page": 1})
# head: FilterError: Can't compare a value of type 'int' with a value of type 'dict' ...
# base: TypeError
non-blocking: one list-valued doc still fails the whole query, where None doesn't match. I'd keep raising, like bad date strings.
This branch has not been deployed
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.
Related Issues
InMemoryDocumentStore.Proposed Changes:
>,>=,<and<=filters raised a rawTypeErrorwhen a document stored a list or dict in the filtered field. For example,{"field": "meta.page", "operator": ">", "value": 1}fails on a store containingDocument(meta={"page": [1, 2]})withTypeError: '>' not supported between instances of 'list' and 'int'. One such document is enough to break the filter for the whole store, and callers catchingFilterErrordon't catch it.These operators already raise
FilterErrorfor other incomparable values (a non-date string, or a list as the filter value). This change routes the final comparison through a small_comparehelper that turns theTypeErrorinto aFilterErrorwith the two types in the message.How did you test it?
test_document_matches_filter_raises_filter_error_for_incomparable_document_value(4 operators x list and dict document values). All 8 cases fail onmainwithTypeErrorand pass with this changehatch run test:unit test/utils/test_filters.py: 166 passedhatch run test:types: no issues in 568 source fileshatch run fmt: cleanNotes for the reviewer
I put the test in
test/utils/test_filters.pyrather than theFilterDocumentsTestmixin, because the mixin also runs against external document stores that filter natively and may legitimately handle this case differently.This PR was fully generated with an AI assistant (Claude Code). I have reviewed the changes and run the relevant tests.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.