From c041bf55e0d4860015f977190e74486cdcef4ace Mon Sep 17 00:00:00 2001 From: Lisandro Navarra Date: Thu, 13 Aug 2026 22:07:06 -0500 Subject: [PATCH] fix(checkpoint-postgres,checkpoint-sqlite): normalize Mapping values to dict before JSON serialization The widened Mapping[str, Any] type on Store.put()/aput() let non-dict Mappings (e.g. UserDict, MappingProxyType) pass type-checking, but checkpoint-sqlite and checkpoint-postgres only had a type-checker-only cast(dict, op.value) rather than an actual runtime conversion, so these values would raise TypeError from orjson/json during serialization. InMemoryStore already normalized via dict(op.value); apply the same normalization here. Caught by open-swe's automated review on this PR. --- libs/checkpoint-postgres/langgraph/store/postgres/base.py | 4 ++-- libs/checkpoint-sqlite/langgraph/store/sqlite/base.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/checkpoint-postgres/langgraph/store/postgres/base.py b/libs/checkpoint-postgres/langgraph/store/postgres/base.py index 100e1e2d3..c407f26f1 100644 --- a/libs/checkpoint-postgres/langgraph/store/postgres/base.py +++ b/libs/checkpoint-postgres/langgraph/store/postgres/base.py @@ -7,7 +7,7 @@ import logging import re import threading from collections import defaultdict -from collections.abc import Callable, Iterable, Iterator, Sequence +from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from contextlib import contextmanager from datetime import datetime from typing import ( @@ -354,7 +354,7 @@ class BasePostgresStore(Generic[C]): ( _namespace_to_text(op.namespace), op.key, - Jsonb(cast(dict, op.value)), + Jsonb(dict(cast(Mapping[str, Any], op.value))), ) ) if op.ttl is not None: diff --git a/libs/checkpoint-sqlite/langgraph/store/sqlite/base.py b/libs/checkpoint-sqlite/langgraph/store/sqlite/base.py index 70d4481cd..fbc23beda 100644 --- a/libs/checkpoint-sqlite/langgraph/store/sqlite/base.py +++ b/libs/checkpoint-sqlite/langgraph/store/sqlite/base.py @@ -7,7 +7,7 @@ import re import sqlite3 import threading from collections import defaultdict -from collections.abc import Callable, Iterable, Iterator, Sequence +from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from contextlib import contextmanager from typing import Any, Literal, NamedTuple, cast @@ -387,7 +387,7 @@ class BaseSqliteStore: [ _namespace_to_text(op.namespace), op.key, - orjson.dumps(cast(dict, op.value)), + orjson.dumps(dict(cast(Mapping[str, Any], op.value))), expires_at, op.ttl, ]