Skip to content

Fix empty list filter raising IndexError instead of WeaviateInvalidInputError#1942

Open
metawake wants to merge 1 commit intoweaviate:mainfrom
metawake:fix/empty-list-filter-exception
Open

Fix empty list filter raising IndexError instead of WeaviateInvalidInputError#1942
metawake wants to merge 1 commit intoweaviate:mainfrom
metawake:fix/empty-list-filter-exception

Conversation

@metawake
Copy link

Summary

  • Passing an empty list to filter methods (.equal([]), .not_equal([]), .less_than([]), .less_or_equal([]), .greater_than([]), .greater_or_equal([])) caused an IndexError: list index out of range because the code accessed value[0] without checking if the list was empty.
  • Added inline empty-list validation to raise a descriptive WeaviateInvalidInputError in each affected method, matching the existing pattern used by contains_any/contains_all/contains_none.
  • Added defense-in-depth guards in the gRPC and REST converter methods (_FilterToGRPC, _FilterToREST) to prevent IndexError if an empty list reaches the serialization layer.

Closes #933

Files changed

  • weaviate/collections/classes/filters.py — inline empty-list checks in equal, not_equal, less_than, less_or_equal, greater_than, greater_or_equal
  • weaviate/collections/filters.py — guards in _FilterToGRPC list methods and _FilterToREST.__parse_filter
  • test/collection/test_filter.py — 6 new unit tests covering each affected filter method

Design note

The empty-list validation is intentionally inlined in each method rather than extracted into a shared helper, to stay consistent with how contains_any/contains_all/contains_none already handle validation in this codebase.

Test plan

  • pytest test/collection/test_filter.py -v — all 30 tests pass (including 6 new)
  • No Docker/Weaviate instance needed — pure client-side validation

Copy link

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

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

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?

@metawake
Copy link
Author

I agree with the CLA!

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.

Throw specific exceptions when attempting filters on empty lists

2 participants