diff --git a/pymilvus/client/check.py b/pymilvus/client/check.py index f171a8512..24f01c15f 100644 --- a/pymilvus/client/check.py +++ b/pymilvus/client/check.py @@ -80,7 +80,8 @@ def is_correct_date_str(param: str) -> bool: def is_legal_dimension(dim: Any) -> bool: try: _ = int(dim) - except ValueError: + except (TypeError, ValueError): + # int() raises TypeError, not ValueError, for a non-numeric type such as None return False return True diff --git a/tests/unit/test_check.py b/tests/unit/test_check.py index 15032f8fd..e1166b8de 100644 --- a/tests/unit/test_check.py +++ b/tests/unit/test_check.py @@ -15,6 +15,7 @@ is_legal_ids, is_legal_port, ) +from pymilvus.exceptions import ParamError from pymilvus.client.utils import ( hybridts_to_unixtime, mkts_from_datetime, @@ -138,6 +139,13 @@ def test_check_param_invalid(self): a = {[i * j for i in range(20) for j in range(20)]} check_pass_param(search_data=a) + @pytest.mark.parametrize("invalid_dimension", [None, [], {}, object()]) + def test_check_pass_param_invalid_dimension(self, invalid_dimension): + # int() raises TypeError rather than ValueError for these, which used to escape + # is_legal_dimension instead of being reported as an illegal parameter + with pytest.raises(ParamError): + check_pass_param(dimension=invalid_dimension) + class TestGenTS: def test_mkts1(self):