diff --git a/test/collection/test_validator.py b/test/collection/test_validator.py index 1f97548b1..6c7e655c5 100644 --- a/test/collection/test_validator.py +++ b/test/collection/test_validator.py @@ -14,6 +14,7 @@ [ (1, [int], False), (1.0, [int], True), + (True, [int], True), ([1, 1], [List], False), (np.array([1, 2, 3]), [_ExtraTypes.NUMPY], False), (np.array([1, 2, 3]), [_ExtraTypes.NUMPY, List], False), diff --git a/weaviate/validator.py b/weaviate/validator.py index 7fe11945c..e9d411dae 100644 --- a/weaviate/validator.py +++ b/weaviate/validator.py @@ -59,4 +59,8 @@ def _is_valid(expected: Any, value: Any) -> bool: return any(isinstance(val, union_arg) for val in value for union_arg in union_args) else: return all(isinstance(val, args[0]) for val in value) + # bool is a subclass of int, so isinstance(True, int) is True. Reject a + # bool where a plain int is expected so it is not silently coerced to 0/1. + if expected is int and isinstance(value, bool): + return False return isinstance(value, expected)