Commit 884db34
committed
Fix Sequence[Union[...]] validation only requiring one element to match
_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.1 parent ae327ca commit 884db34
2 files changed
Lines changed: 29 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
0 commit comments