Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/collection/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions weaviate/collections/classes/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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 "
Expand All @@ -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 "
Expand All @@ -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 "
Expand All @@ -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 "
Expand All @@ -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 "
Expand Down
Loading