Skip to content

Reject empty tuples in filter value builders - #2270

Open
kus-coded wants to merge 1 commit into
weaviate:mainfrom
kus-coded:fix/filter-empty-sequence-2265
Open

kus-coded wants to merge 1 commit into
weaviate:mainfrom
kus-coded:fix/filter-empty-sequence-2265

Conversation

@kus-coded

Copy link
Copy Markdown

Fixes #2265

Problem

Filter.by_property(...).equal(()) and the five sibling builders (not_equal, less_than, less_or_equal, greater_than, greater_or_equal) only rejected empty lists. An empty tuple was accepted, and the WeaviateInvalidInputError only appeared later, when a query converted the filter to gRPC, so the traceback pointed at the query instead of the line that built the filter.

Change

The six checks in weaviate/collections/classes/filters.py now reject any empty non-string sequence (isinstance(val, Sequence) and not isinstance(val, (str, bytes))), matching how _to_value_list treats sequences. str and bytes are excluded so equal("") remains a valid filter.

Tests

  • test_empty_tuple_raises (parametrized over the six methods): fails on main (6 failed), passes with this change.
  • test_empty_string_equal_is_valid: guards that equal("") still works.
  • pytest test/collection/test_filter.py: 83 passed. ruff format --check is clean, and flake8 is clean on the changed files.

AI assistance

I used Claude (Anthropic) to help locate the code and draft the change. I reviewed the diff, ran the tests, and can explain every line.

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 weaviate#2265

@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?

@kus-coded

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement and I agree to it.

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

2 participants