Skip to content

Commit cdef851

Browse files
committed
fix(checkpoint): decode base64 blobs when loading pending writes
Add static _decode_blob_static() method to handle base64 decoding of blob data retrieved from Redis before passing to serializer. This fixes orjson.JSONDecodeError when loading pending writes.
1 parent 66cdd93 commit cdef851

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

langgraph/checkpoint/redis/base.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,25 @@ def _load_writes(
732732
(
733733
task_id,
734734
data["channel"],
735-
serde.loads_typed((data["type"], data["blob"])),
735+
serde.loads_typed((data["type"], BaseRedisSaver._decode_blob_static(data["blob"]))),
736736
)
737737
for (task_id, _), data in task_id_to_data.items()
738738
]
739739
return writes
740740

741+
@staticmethod
742+
def _decode_blob_static(blob: bytes | str) -> bytes:
743+
"""Decode blob data from Redis storage (static method)."""
744+
try:
745+
# If it's already bytes, try to decode as base64
746+
if isinstance(blob, bytes):
747+
return base64.b64decode(blob)
748+
# If it's a string, encode to bytes first then decode
749+
return base64.b64decode(blob.encode("utf-8"))
750+
except (binascii.Error, TypeError, ValueError):
751+
# Handle both malformed base64 data and incorrect input types
752+
return blob.encode("utf-8") if isinstance(blob, str) else blob
753+
741754
@staticmethod
742755
def _parse_redis_checkpoint_writes_key(redis_key: str) -> dict:
743756
# Ensure redis_key is a string

0 commit comments

Comments
 (0)