Skip to content

Fix Sequence[Union[...]] validation only requiring one element to match - #2108

Open
Nimra3261 wants to merge 1 commit into
weaviate:mainfrom
Nimra3261:fix-sequence-union-validation
Open

Fix Sequence[Union[...]] validation only requiring one element to match#2108
Nimra3261 wants to merge 1 commit into
weaviate:mainfrom
Nimra3261:fix-sequence-union-validation

Conversation

@Nimra3261

Copy link
Copy Markdown

Bug

_is_valid's Sequence[Union[X, Y]] branch flattens the per-element check into a single any() across (value, union_arg) pairs:

return any(isinstance(val, union_arg) for val in value for union_arg in union_args)

This means validation passes as soon as one element matches one type in the union, regardless of whether the other elements match anything at all:

>>> _is_valid(Sequence[Union[str, int]], ["a", 3.14])
True  # should be False - 3.14 is neither str nor int

Where this is user-facing

weaviate/collections/tenants/executor.py validates tenants against Sequence[Union[str, Tenant, ...]] in add/remove/update/upsert. A list mixing a valid tenant name/object with something invalid (an accidental int, a stray dict, etc.) currently passes this validation silently and gets forwarded into request-building instead of failing fast with a clear WeaviateInvalidInputError - the exact thing this validation exists to catch.

Fix

Require every element to match at least one union member: all(any(...) for val in value), matching the existing (correct) logic already used two lines below for the non-Union Sequence[X] branch.

Testing

Added regression tests in test/collection/test_validator.py. Verified they fail against the pre-fix code (3 failures, confirming they actually exercise the bug) and pass with the fix. Full test_validator.py file: 19/19 passing.

_is_valid's Sequence[Union[X, Y]] branch flattened the per-element check
into a single any() across (value, union_arg) pairs:

    return any(isinstance(val, union_arg) for val in value for union_arg in union_args)

This means the check passes as soon as ONE element matches ONE type in
the union, regardless of whether other elements in the sequence match
anything at all. E.g. _is_valid(Sequence[Union[str, int]], ["a", 3.14])
returns True even though 3.14 is neither a str nor an int.

This is reachable through real user-facing validation: collection.tenants
add/remove/update/upsert all validate their `tenants` argument against
Sequence[Union[str, Tenant, ...]] (weaviate/collections/tenants/executor.py).
A list mixing a valid tenant name/object with something invalid (e.g. an
accidental int, or a stray dict) currently passes validation silently and
gets sent to the request-building code instead of failing fast with a
clear WeaviateInvalidInputError - the exact thing this argument
validation exists to prevent.

Fixed to require every element to match at least one union member:
all(any(...) for val in value), matching the existing (correct) logic
for the non-Union Sequence[X] branch two lines below it.

Added regression tests in test/collection/test_validator.py - verified
they fail against the pre-fix code (3 failures) and pass with the fix.

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

@Nimra3261

Copy link
Copy Markdown
Author

I agree to the Contributor License Agreement.

@Nimra3261 Nimra3261 closed this Jul 29, 2026
@Nimra3261 Nimra3261 reopened this Jul 29, 2026
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