mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-28 12:35:08 +02:00
langgraph: fix None handling for pydantic state updates
This commit is contained in:
@@ -33,7 +33,7 @@ from langgraph.channels.dynamic_barrier_value import DynamicBarrierValue, WaitFo
|
||||
from langgraph.channels.ephemeral_value import EphemeralValue
|
||||
from langgraph.channels.last_value import LastValue
|
||||
from langgraph.channels.named_barrier_value import NamedBarrierValue
|
||||
from langgraph.constants import EMPTY_SEQ, NS_END, NS_SEP, SELF, TAG_HIDDEN
|
||||
from langgraph.constants import EMPTY_SEQ, MISSING, NS_END, NS_SEP, SELF, TAG_HIDDEN
|
||||
from langgraph.errors import (
|
||||
ErrorCode,
|
||||
InvalidUpdateError,
|
||||
@@ -694,7 +694,7 @@ class CompiledStateGraph(CompiledGraph):
|
||||
return [
|
||||
(k, getattr(input, k))
|
||||
for k in output_keys
|
||||
if getattr(input, k, None) is not None
|
||||
if getattr(input, k, MISSING) is not MISSING
|
||||
]
|
||||
else:
|
||||
msg = create_error_message(
|
||||
|
||||
@@ -6482,3 +6482,16 @@ def test_node_destinations() -> None:
|
||||
Edge(source="child", target="node_b", data="foo", conditional=True),
|
||||
Edge(source="child", target="node_c", data="bar", conditional=True),
|
||||
] == graph.edges
|
||||
|
||||
|
||||
def test_pydantic_none_state_update() -> None:
|
||||
from pydantic import BaseModel
|
||||
|
||||
class State(BaseModel):
|
||||
foo: str | None
|
||||
|
||||
def node_a(state: State) -> State:
|
||||
return State(foo=None)
|
||||
|
||||
graph = StateGraph(State).add_node(node_a).add_edge(START, "node_a").compile()
|
||||
assert graph.invoke({"foo": ""}) == {"foo": None}
|
||||
|
||||
Reference in New Issue
Block a user