From d3585a841bf77c71c3fca23a5d6827767e7c8f8e Mon Sep 17 00:00:00 2001 From: Unmilan Mukherjee <52813146+Missing-Identity@users.noreply.github.com> Date: Mon, 13 Jul 2026 02:09:24 +0530 Subject: [PATCH] fix: resolve flaky tenant input validation in Python 3.12 (#1355) Replaces typing.Sequence with collections.abc.Sequence for runtime type-checking to avoid flaky behavior in Python 3.12+. Signed-off-by: Unmilan Mukherjee --- weaviate/validator.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/weaviate/validator.py b/weaviate/validator.py index 7fe11945c..7d70b586b 100644 --- a/weaviate/validator.py +++ b/weaviate/validator.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +import collections.abc from typing import Any, List, Sequence, Union, get_args, get_origin from weaviate.exceptions import WeaviateInvalidInputError @@ -47,16 +48,25 @@ def _is_valid(expected: Any, value: Any) -> bool: if expected_origin is Union: args = get_args(expected) return any(isinstance(value, arg) for arg in args) + + # FIX for #1355: Use collections.abc.Sequence for robust runtime check in Python 3.12 if expected_origin is not None and ( - issubclass(expected_origin, Sequence) or expected_origin is list + issubclass(expected_origin, collections.abc.Sequence) or expected_origin is list ): - if not isinstance(value, Sequence) and not isinstance(value, list): + if not isinstance(value, (collections.abc.Sequence, list)): return False args = get_args(expected) if len(args) == 1: if get_origin(args[0]) is Union: union_args = get_args(args[0]) - return any(isinstance(val, union_arg) for val in value for union_arg in union_args) + # Ensure every element in the sequence matches the Union types + return all(any(isinstance(val, union_arg) for union_arg in union_args) for val in value) else: return all(isinstance(val, args[0]) for val in value) - return isinstance(value, expected) + + try: + return isinstance(value, expected) + except TypeError: + if expected_origin is not None: + return isinstance(value, expected_origin) + return False