From b289b564358902cbed62b46f25b780599bc07ea5 Mon Sep 17 00:00:00 2001 From: Nishchay Mahor Date: Sun, 5 Jul 2026 00:39:45 -0700 Subject: [PATCH] Reject bool where a plain int is expected in _is_valid bool is a subclass of int, so isinstance(True, int) is True and _is_valid accepted a bool wherever a bare int was expected (e.g. query limit/offset/ autocut), silently coercing True/False to 1/0 instead of raising WeaviateInvalidInputError. Guard the int case, mirroring the bool/int fix in config.py from #2077. Adds a validator unit-test case. --- test/collection/test_validator.py | 1 + weaviate/validator.py | 4 ++++ 2 files changed, 5 insertions(+) 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)