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
56 changes: 56 additions & 0 deletions test/test_where_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Unit tests for the GraphQL `Where` filter string rendering.

These do not require a running Weaviate instance; they pin the exact GraphQL
fragments produced client-side.
"""

from weaviate.gql.filter import Where


def test_boolean_list_is_rendered_as_lowercase_graphql_literals() -> None:
"""A boolean list must render as lowercase GraphQL booleans.

Regression: booleans in a list were rendered with Python's ``str()`` which
emits ``True``/``False`` (capitalized). That is not a valid GraphQL boolean
literal and made the whole aggregate query fail to parse server-side,
whereas a single boolean value was already rendered correctly.
"""
for value_type in ["valueBooleanArray", "valueBooleanList"]:
where = Where(
{
"operator": "ContainsAny",
"path": ["active"],
value_type: [True, False, True],
}
)
rendered = str(where)
assert "[true,false,true]" in rendered, rendered
assert "True" not in rendered and "False" not in rendered, rendered


def test_single_boolean_rendering_is_unchanged() -> None:
where = Where({"operator": "Equal", "path": ["active"], "valueBoolean": True})
assert "valueBoolean: true" in str(where)

where = Where({"operator": "Equal", "path": ["active"], "valueBoolean": False})
assert "valueBoolean: false" in str(where)


def test_other_lists_rendering_is_unchanged() -> None:
string_list = Where(
{
"operator": "ContainsAny",
"path": ["name"],
"valueStringArray": ["a", "b"],
}
)
assert 'valueString: ["a","b"]' in str(string_list)

int_list = Where(
{
"operator": "ContainsAny",
"path": ["count"],
"valueIntArray": [1, 2],
}
)
assert "valueInt: [1, 2]" in str(int_list)
5 changes: 4 additions & 1 deletion weaviate/gql/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,10 @@ def __str__(self) -> str:
if self.value_type in ["valueBooleanArray", "valueBooleanList"]:
_check_is_list(self.value, self.value_type)
if isinstance(self.value, list):
gql += f"{_render_list(self.value)}}}"
# Render each boolean as a lowercase GraphQL literal, matching
# the single-value branch above; str(True) would emit "True",
# which is not a valid GraphQL boolean and breaks parsing.
gql += f"{_render_list([_bool_to_str(v) for v in self.value])}}}"
else:
gql += f"{_bool_to_str(self.value)}}}"
elif self.value_type in ["valueDateArray", "valueDateList"]:
Expand Down
Loading