Skip to content

Commit ff142ec

Browse files
committed
fix: use _default handler instead of non-existent super().dumps()
The bug was in line 28 where super().dumps(obj) was called, but the parent class JsonPlusSerializer doesn't have a dumps() method. The correct fix is to use orjson.dumps() with default=self._default, which properly delegates LangChain object serialization to the parent's _default method.
1 parent 0e7fec0 commit ff142ec

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

langgraph/checkpoint/redis/jsonplus_redis.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,10 @@ class JsonPlusRedisSerializer(JsonPlusSerializer):
3939
]
4040

4141
def dumps(self, obj: Any) -> bytes:
42-
"""Use orjson for simple objects, fallback to msgpack for complex objects."""
43-
try:
44-
# Fast path: Use orjson for JSON-serializable objects
45-
return orjson.dumps(obj)
46-
except TypeError:
47-
# Complex objects (Send, etc.) need parent's serialization
48-
# Parent's dumps_typed returns (type, data) where data is already encoded
49-
type_, data = super().dumps_typed(obj)
50-
# Data from dumps_typed is already in the correct format (string or bytes)
51-
# For msgpack type, data is bytes; for json type, data is string
52-
if isinstance(data, bytes):
53-
return data
54-
else:
55-
return data.encode("utf-8")
42+
"""Use orjson for serialization with LangChain object support via default handler."""
43+
# Use orjson with default handler for LangChain objects
44+
# The _default method from parent class handles LangChain serialization
45+
return orjson.dumps(obj, default=self._default)
5646

5747
def loads(self, data: bytes) -> Any:
5848
"""Use orjson for JSON parsing with reviver support, fallback to parent for msgpack data."""
@@ -106,6 +96,7 @@ def dumps_typed(self, obj: Any) -> tuple[str, str]: # type: ignore[override]
10696
if isinstance(obj, (bytes, bytearray)):
10797
return "base64", base64.b64encode(obj).decode("utf-8")
10898
else:
99+
# All objects should be JSON-serializable (LangChain objects are pre-serialized)
109100
return "json", self.dumps(obj).decode("utf-8")
110101

111102
def loads_typed(self, data: tuple[str, Union[str, bytes]]) -> Any:

0 commit comments

Comments
 (0)