Skip to content

Commit 9818255

Browse files
authored
Merge pull request #2088 from NishchayMahor/fix/validator-reject-bool-as-int
Reject bool where a plain int is expected in _is_valid
2 parents 6cf2d2e + b289b56 commit 9818255

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

test/collection/test_validator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
[
1515
(1, [int], False),
1616
(1.0, [int], True),
17+
(True, [int], True),
1718
([1, 1], [List], False),
1819
(np.array([1, 2, 3]), [_ExtraTypes.NUMPY], False),
1920
(np.array([1, 2, 3]), [_ExtraTypes.NUMPY, List], False),

weaviate/validator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ def _is_valid(expected: Any, value: Any) -> bool:
5959
return any(isinstance(val, union_arg) for val in value for union_arg in union_args)
6060
else:
6161
return all(isinstance(val, args[0]) for val in value)
62+
# bool is a subclass of int, so isinstance(True, int) is True. Reject a
63+
# bool where a plain int is expected so it is not silently coerced to 0/1.
64+
if expected is int and isinstance(value, bool):
65+
return False
6266
return isinstance(value, expected)

0 commit comments

Comments
 (0)