Skip to content

fix(gql): render boolean where-filter lists as lowercase GraphQL literals - #2192

Open
linhongyu510 wants to merge 1 commit into
weaviate:mainfrom
linhongyu510:fix/where-boolean-list-lowercase
Open

linhongyu510 wants to merge 1 commit into
weaviate:mainfrom
linhongyu510:fix/where-boolean-list-lowercase

Conversation

@linhongyu510

Copy link
Copy Markdown

What

Boolean where-filter lists were rendered into the aggregate GraphQL query with Python's str(), emitting capitalized True/False. Those are not valid GraphQL boolean literals, so a where filter containing a boolean list produced a query the server rejects at parse time.

The single-boolean path already rendered correctly via _bool_to_str() (true/false); only the list path was wrong — an asymmetry between the two branches.

Reproduction

Building an aggregate query with a boolean list filter (reachable through the public Filter DSL):

from weaviate.collections.classes.filters import Filter
from weaviate.collections.filters import _FilterToREST
from weaviate.gql.aggregate import AggregateBuilder

b = AggregateBuilder("Question")
b.with_where(_FilterToREST.convert(Filter.by_property("active").contains_any([True, False]))).with_meta_count()
print(b.build())

Before:

{Aggregate{Question(where: {path: ["active"] operator: ContainsAny valueBoolean: [True,False]} ){meta{count}}}}

([True,False] is invalid GraphQL — the server fails to parse the query.)

After:

{Aggregate{Question(where: {path: ["active"] operator: ContainsAny valueBoolean: [true,false]} ){meta{count}}}}

Root cause

In Where.__str__ (weaviate/gql/filter.py), the boolean branch used _render_list(self.value) for list values, which joins with str(item). str(True) is "True". The non-list branch correctly used _bool_to_str. The fix maps _bool_to_str over each list element, matching the single-value branch.

This affects valueBooleanArray / valueBooleanList (e.g. Filter.by_property(...).contains_any([...]) / contains_all([...]) with booleans) in aggregate queries built by AggregateBuilder.

Tests

Added test/test_where_filter.py (pure unit tests, no live server):

  • boolean list renders as lowercase [true,false,true] and contains no True/False (regression — fails on the old code)
  • single boolean rendering is unchanged
  • string/int list rendering is unchanged

Existing test/collection/test_filter.py and test/test_util.py continue to pass.

…rals

Boolean where-filter lists (valueBooleanArray/valueBooleanList) were rendered
via str(), emitting capitalized 'True'/'False', which is not a valid GraphQL
boolean literal and breaks server-side query parsing. A single boolean value
was already rendered correctly by _bool_to_str(); this applies the same
lowercasing to list elements for consistency.

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@weaviate-git-bot

Copy link
Copy Markdown

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Forum?

@linhongyu510

Copy link
Copy Markdown
Author

I agree to the Weaviate Contributor License Agreement.

Transparency note: this change was prepared with AI assistance (bug localization, patch drafting, and regression tests). I have reviewed the final diff line by line against the existing code paths — the single-boolean branch already rendered lowercase via _bool_to_str(); this only applies the same lowercasing to list elements — and verified the before/after GraphQL output locally. No other call sites or list types (string/int/date) were changed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants