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 "