From 018e9ac42e38f43c8618be977283c7c0254bfd67 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:55:30 -0700 Subject: [PATCH] Check is string in store namespace validation (on put) (#2007) --- libs/checkpoint/langgraph/store/base/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/checkpoint/langgraph/store/base/__init__.py b/libs/checkpoint/langgraph/store/base/__init__.py index a4e69a848..8d11a3015 100644 --- a/libs/checkpoint/langgraph/store/base/__init__.py +++ b/libs/checkpoint/langgraph/store/base/__init__.py @@ -162,12 +162,19 @@ def _validate_namespace(namespace: tuple[str, ...]) -> None: if not namespace: raise InvalidNamespaceError("Namespace cannot be empty.") for label in namespace: + if not isinstance(label, str): + raise InvalidNamespaceError( + f"Invalid namespace label '{label}' found in {namespace}. Namespace labels" + f" must be strings, but got {type(label).__name__}." + ) if "." in label: raise InvalidNamespaceError( - f"Invalid namespace label '{label}'. Namespace labels cannot contain periods ('.')." + f"Invalid namespace label '{label}' found in {namespace}. Namespace labels cannot contain periods ('.')." ) elif not label: - raise InvalidNamespaceError("Namespace labels cannot be empty strings.") + raise InvalidNamespaceError( + f"Namespace labels cannot be empty strings. Got {label} in {namespace}" + ) if namespace[0] == "langgraph": raise InvalidNamespaceError( f'Root label for namespace cannot be "langgraph". Got: {namespace}'