mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-12 12:47:53 +02:00
fix(checkpoint/serde): use lazy isinstance check for DiffDelta
Replace duck-typing check with lazy import inside _is_diff_delta helper function to avoid module-level circular dependency while using proper isinstance semantics. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
9e40dee07f
commit
3f86b1485d
@@ -47,6 +47,11 @@ EMPTY_BYTES = b""
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _is_diff_delta(obj: Any) -> bool:
|
||||
from langgraph.checkpoint.base import DiffDelta # lazy import avoids circular dep
|
||||
return isinstance(obj, DiffDelta)
|
||||
|
||||
|
||||
class JsonPlusSerializer(SerializerProtocol):
|
||||
"""Serializer that uses ormsgpack, with optional fallbacks.
|
||||
|
||||
@@ -239,11 +244,7 @@ class JsonPlusSerializer(SerializerProtocol):
|
||||
return "bytes", obj
|
||||
elif isinstance(obj, bytearray):
|
||||
return "bytearray", obj
|
||||
elif (
|
||||
type(obj).__name__ == "DiffDelta"
|
||||
and hasattr(obj, "delta")
|
||||
and hasattr(obj, "prev_version")
|
||||
):
|
||||
elif _is_diff_delta(obj):
|
||||
return "diff", _msgpack_enc({"d": obj.delta, "p": obj.prev_version})
|
||||
else:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user