Skip to content

fix: throw specific exception on empty list filters for time filters#2004

Open
Maanik23 wants to merge 1 commit intoweaviate:mainfrom
Maanik23:fix/empty-list-time-filter
Open

fix: throw specific exception on empty list filters for time filters#2004
Maanik23 wants to merge 1 commit intoweaviate:mainfrom
Maanik23:fix/empty-list-time-filter

Conversation

@Maanik23
Copy link
Copy Markdown

@Maanik23 Maanik23 commented Apr 7, 2026

Fixes #933

Summary

The _FilterByTime class (used by by_creation_time() and by_update_time()) was missing the empty list validation that other filter classes already have. Calling contains_any([]) or contains_none([]) on a time filter would silently produce a malformed filter instead of raising a clear error.

This brings _FilterByTime in line with _FilterByProperty and _FilterById, which already raise `WeaviateInvalidInputError` for empty input.

Changes

`weaviate/collections/classes/filters.py`

  • Added `if len(dates) == 0` check to `_FilterByTime.contains_any()`
  • Added `if len(dates) == 0` check to `_FilterByTime.contains_none()`
  • Both raise `WeaviateInvalidInputError` with the same message format used elsewhere

`test/collection/test_filter.py`

  • Extended `test_empty_input_contains_any` with cases for `by_creation_time()` and `by_update_time()`
  • Added `test_empty_input_contains_none_time` covering `contains_none([])` on both time filter types

Why this matters

Without these checks, code like:

```python
collection.query.fetch_objects(
filters=Filter.by_creation_time().contains_any([])
)
```

would either crash with an opaque `IndexError` deep in the gRPC layer or send a malformed filter to the server. After this PR it raises a clear `WeaviateInvalidInputError` at construction time, matching the existing UX for property and ID filters.

Test plan

  • Added unit tests for both `contains_any([])` and `contains_none([])` on `by_creation_time()` and `by_update_time()`
  • Existing tests in `test_filter.py` continue to pass (no behavior change for non-empty inputs)
  • Error message matches the existing format used in `_FilterByProperty` and `_FilterById`

The _FilterByTime class (used by by_creation_time and by_update_time)
was missing the empty list validation that other filter classes already
have. Calling contains_any([]) or contains_none([]) on a time filter
would silently produce a malformed filter rather than raising a clear
error.

Added the same WeaviateInvalidInputError check used by _FilterByProperty
and _FilterById, plus tests for both contains_any and contains_none on
both creation_time and update_time filters.

Fixes weaviate#933
Copy link
Copy Markdown

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

@Maanik23
Copy link
Copy Markdown
Author

Maanik23 commented Apr 8, 2026

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

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