Skip to content

Commit 7b46153

Browse files
5enxiaCopilot
andauthored
Update libs/langgraph-checkpoint-aws/langgraph_checkpoint_aws/store/dynamodb/base.py
Co-authored-by: Copilot <[email protected]>
1 parent 32da9a4 commit 7b46153

File tree

1 file changed

+16
-5
lines changed
  • libs/langgraph-checkpoint-aws/langgraph_checkpoint_aws/store/dynamodb

1 file changed

+16
-5
lines changed

libs/langgraph-checkpoint-aws/langgraph_checkpoint_aws/store/dynamodb/base.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,34 @@ def _construct_composite_key(
278278
Returns:
279279
Tuple of (PK, SK) for DynamoDB.
280280
"""
281-
namespace_str = ":".join(namespace)
281+
# Serialize namespace tuple as JSON string for unambiguous encoding
282+
namespace_str = orjson.dumps(namespace).decode("utf-8")
282283
return (namespace_str, key)
283284

284285
def _deconstruct_namespace(self, namespace: str) -> tuple[str, ...]:
285286
"""Deconstruct namespace string back to tuple.
286287
287288
Args:
288-
namespace: Namespace string (e.g., "users:123").
289+
namespace: Namespace string (JSON-encoded).
289290
290291
Returns:
291292
Namespace tuple (e.g., ("users", "123")).
292293
"""
293294
if not namespace:
294295
return ()
295-
if ":" in namespace:
296-
return tuple(namespace.split(":"))
297-
return (namespace,)
296+
try:
297+
# Deserialize JSON string back to tuple
298+
ns = orjson.loads(namespace)
299+
# Ensure result is tuple
300+
if isinstance(ns, (list, tuple)):
301+
return tuple(ns)
302+
# Fallback: single string
303+
return (str(ns),)
304+
except Exception:
305+
# Fallback for legacy colon-separated format
306+
if ":" in namespace:
307+
return tuple(namespace.split(":"))
308+
return (namespace,)
298309

299310
def _map_to_item(self, result_dict: dict[str, Any], item_type: type = Item) -> Item:
300311
"""Map DynamoDB item to store Item.

0 commit comments

Comments
 (0)