From 37096ee66af6fa36230141a1c5356bcdc192f735 Mon Sep 17 00:00:00 2001 From: Kushal Kumar Date: Wed, 18 Nov 2026 21:11:40 +0530 Subject: [PATCH] Reject empty tuples and other empty sequences in filter value builders equal, not_equal, less_than, less_or_equal, greater_than and greater_or_equal only rejected empty lists, so an empty tuple was accepted and failed later at query time. Reject any empty non-string sequence at build time. str and bytes are excluded so equal('') stays valid. Fixes #2265 --- test/collection/test_filter.py | 17 +++++++++++++++++ weaviate/collections/classes/filters.py | 12 ++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/test/collection/test_filter.py b/test/collection/test_filter.py index 760e4e46f..d70fa6cea 100644 --- a/test/collection/test_filter.py +++ b/test/collection/test_filter.py @@ -71,6 +71,23 @@ def test_empty_list_greater_or_equal() -> None: wvc.query.Filter.by_property("test").greater_or_equal([]) +@pytest.mark.parametrize( + "method", + ["equal", "not_equal", "less_than", "less_or_equal", "greater_than", "greater_or_equal"], +) +def test_empty_tuple_raises(method: str) -> None: + """An empty tuple must be rejected at build time, the same as an empty list.""" + with pytest.raises(weaviate.exceptions.WeaviateInvalidInputError): + getattr(wvc.query.Filter.by_property("test"), method)(()) + + +def test_empty_string_equal_is_valid() -> None: + """Empty strings are valid filter values and must not be rejected as empty sequences.""" + f = wvc.query.Filter.by_property("test").equal("") + assert isinstance(f, _FilterValue) + assert f.value == "" + + def test_empty_list_grpc_conversion() -> None: """Ensure the gRPC converter raises WeaviateInvalidInputError for empty lists.""" fv = _FilterValue(target="test", value=[], operator=_Operator.EQUAL) diff --git a/weaviate/collections/classes/filters.py b/weaviate/collections/classes/filters.py index 100842664..f5989cb2f 100644 --- a/weaviate/collections/classes/filters.py +++ b/weaviate/collections/classes/filters.py @@ -222,7 +222,7 @@ def contains_none(self, val: FilterValuesList) -> _Filters: def equal(self, val: FilterValues) -> _Filters: """Filter on whether the property is equal to the given value.""" - if isinstance(val, list) and len(val) == 0: + if isinstance(val, Sequence) and not isinstance(val, (str, bytes)) and len(val) == 0: raise WeaviateInvalidInputError( "Filtering on empty lists is not supported by Weaviate. " "To filter by property length, use " @@ -232,7 +232,7 @@ def equal(self, val: FilterValues) -> _Filters: def not_equal(self, val: FilterValues) -> _Filters: """Filter on whether the property is not equal to the given value.""" - if isinstance(val, list) and len(val) == 0: + if isinstance(val, Sequence) and not isinstance(val, (str, bytes)) and len(val) == 0: raise WeaviateInvalidInputError( "Filtering on empty lists is not supported by Weaviate. " "To filter by property length, use " @@ -242,7 +242,7 @@ def not_equal(self, val: FilterValues) -> _Filters: def less_than(self, val: FilterValues) -> _Filters: """Filter on whether the property is less than the given value.""" - if isinstance(val, list) and len(val) == 0: + if isinstance(val, Sequence) and not isinstance(val, (str, bytes)) and len(val) == 0: raise WeaviateInvalidInputError( "Filtering on empty lists is not supported by Weaviate. " "To filter by property length, use " @@ -252,7 +252,7 @@ def less_than(self, val: FilterValues) -> _Filters: def less_or_equal(self, val: FilterValues) -> _Filters: """Filter on whether the property is less than or equal to the given value.""" - if isinstance(val, list) and len(val) == 0: + if isinstance(val, Sequence) and not isinstance(val, (str, bytes)) and len(val) == 0: raise WeaviateInvalidInputError( "Filtering on empty lists is not supported by Weaviate. " "To filter by property length, use " @@ -266,7 +266,7 @@ def less_or_equal(self, val: FilterValues) -> _Filters: def greater_than(self, val: FilterValues) -> _Filters: """Filter on whether the property is greater than the given value.""" - if isinstance(val, list) and len(val) == 0: + if isinstance(val, Sequence) and not isinstance(val, (str, bytes)) and len(val) == 0: raise WeaviateInvalidInputError( "Filtering on empty lists is not supported by Weaviate. " "To filter by property length, use " @@ -280,7 +280,7 @@ def greater_than(self, val: FilterValues) -> _Filters: def greater_or_equal(self, val: FilterValues) -> _Filters: """Filter on whether the property is greater than or equal to the given value.""" - if isinstance(val, list) and len(val) == 0: + if isinstance(val, Sequence) and not isinstance(val, (str, bytes)) and len(val) == 0: raise WeaviateInvalidInputError( "Filtering on empty lists is not supported by Weaviate. " "To filter by property length, use "