Skip to content

Commit fe48e7f

Browse files
authored
fix(checkpoint): update blob access to support JSON path syntax (#117)
Modified the AsyncRedisSaver to access the blob attribute using JSON path syntax. Enhanced the sorting mechanism for parent checkpoints and ensured the results map correctly extracts type and blob pairs, accommodating both direct and JSON path access. This improves compatibility and consistency in data handling.
1 parent 4919e23 commit fe48e7f

File tree

1 file changed

+19
-12
lines changed
  • langgraph/checkpoint/redis

1 file changed

+19
-12
lines changed

langgraph/checkpoint/redis/aio.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ async def _abatch_load_pending_sends(
17241724
return_fields=[
17251725
"checkpoint_id",
17261726
"type",
1727-
"blob",
1727+
"$.blob",
17281728
"task_path",
17291729
"task_id",
17301730
"idx",
@@ -1745,20 +1745,27 @@ async def _abatch_load_pending_sends(
17451745
# Sort and format results for each parent checkpoint
17461746
for parent_checkpoint_id in parent_checkpoint_ids:
17471747
batch_key = (thread_id, checkpoint_ns, parent_checkpoint_id)
1748-
docs = writes_by_checkpoint.get(parent_checkpoint_id, [])
1749-
1750-
# Sort for deterministic order
1751-
sorted_docs = sorted(
1752-
docs,
1753-
key=lambda d: (
1754-
getattr(d, "task_path", ""),
1755-
getattr(d, "task_id", ""),
1756-
getattr(d, "idx", 0),
1748+
writes = writes_by_checkpoint.get(parent_checkpoint_id, [])
1749+
1750+
# Sort results by task_path, task_id, idx
1751+
sorted_writes = sorted(
1752+
writes,
1753+
key=lambda x: (
1754+
getattr(x, "task_path", ""),
1755+
getattr(x, "task_id", ""),
1756+
getattr(x, "idx", 0),
17571757
),
17581758
)
17591759

1760-
# Convert to expected format
1761-
results_map[batch_key] = [(d.type, d.blob) for d in sorted_docs]
1760+
# Extract type and blob pairs
1761+
# Handle both direct attribute access and JSON path access
1762+
results_map[batch_key] = [
1763+
(
1764+
getattr(doc, "type", ""),
1765+
getattr(doc, "$.blob", getattr(doc, "blob", b"")),
1766+
)
1767+
for doc in sorted_writes
1768+
]
17621769

17631770
return results_map
17641771

0 commit comments

Comments
 (0)