mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-06 17:57:49 +02:00
Validate not empty (#1957)
This commit is contained in:
@@ -159,11 +159,15 @@ class InvalidNamespaceError(ValueError):
|
||||
|
||||
|
||||
def _validate_namespace(namespace: tuple[str, ...]) -> None:
|
||||
if not namespace:
|
||||
raise ValueError("Namespace cannot be empty.")
|
||||
for label in namespace:
|
||||
if "." in label:
|
||||
raise InvalidNamespaceError(
|
||||
f"Invalid namespace label '{label}'. Namespace labels cannot contain periods ('.')."
|
||||
)
|
||||
elif not label:
|
||||
raise ValueError("Namespace labels cannot be empty strings.")
|
||||
|
||||
|
||||
class BaseStore(ABC):
|
||||
|
||||
@@ -2,9 +2,10 @@ import asyncio
|
||||
from datetime import datetime
|
||||
from typing import Iterable
|
||||
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from langgraph.store.base import GetOp, Item, Op, Result
|
||||
from langgraph.store.base import GetOp, InvalidNamespaceError, Item, Op, Result
|
||||
from langgraph.store.base.batch import AsyncBatchedBaseStore
|
||||
from langgraph.store.memory import InMemoryStore
|
||||
|
||||
@@ -259,3 +260,26 @@ def test_list_namespaces_empty_store() -> None:
|
||||
|
||||
result = store.list_namespaces()
|
||||
assert result == []
|
||||
|
||||
|
||||
async def test_cannot_put_empty_namespace() -> None:
|
||||
store = InMemoryStore()
|
||||
doc = {"foo": "bar"}
|
||||
|
||||
with pytest.raises(InvalidNamespaceError):
|
||||
store.put([], "foo", doc)
|
||||
|
||||
with pytest.raises(InvalidNamespaceError):
|
||||
await store.aput([], "foo", doc)
|
||||
|
||||
with pytest.raises(InvalidNamespaceError):
|
||||
store.put(["the", "thing.about"], "foo", doc)
|
||||
|
||||
with pytest.raises(InvalidNamespaceError):
|
||||
await store.aput(["the", "thing.about"], "foo", doc)
|
||||
|
||||
with pytest.raises(InvalidNamespaceError):
|
||||
store.put(["some", "fun", ""], "foo", doc)
|
||||
|
||||
with pytest.raises(InvalidNamespaceError):
|
||||
await store.aput(["some", "fun", ""], "foo", doc)
|
||||
|
||||
Reference in New Issue
Block a user