mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-17 21:25:46 +02:00
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.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user