#8942·langgraph

SqliteSaver.put 在检查点中出现元数据包含旧的 `writes` 关键字时会引发 TypeError (在 #6236 中已修复对 Postgres 的问题)

作者: Hotragn创建于 2026年9月16日更新于 2026年9月17日
标签external

Reproduction Steps / Example Code (Python)

python
from langchain_core.messages import AIMessage
from LangGraph.checkpoint.sqlite import SqliteSaver
config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}}
checkpoint = {
    "v": 1,
    "id": "1ef4f797-8335-6428-8001-8a1503f9b875",
    "ts": "2024-05-04T06:32:42.235444+00:00",
    "channel_values": {"messages": []},
    "channel_versions": {},
    "versions_seen": {},
}
# metadata exactly as an older LangGraph version wrote it
metadata = {
    "source": "loop",
    "step": 1,
    "writes": {"agent": {"messages": [AIMessage(content="hi")]}},
}
with SqliteSaver.from_conn_string(":memory:") as saver:
    saver.put(config, checkpoint, metadata, {})
    print("stored:", saver.get_tuple(config).metadata)

Error Message and Stack Trace (if applicable)

  File ".../issue_repro.py", line 21, in <module>
    saver.put(config, checkpoint, metadata, {})
  File ".../LangGraph/checkpoint/sqlite/__init__.py", line 421, in put
    serialized_metadata = json.dumps(
  ...
TypeError: Object of type AIMessage is not JSON serializable

AsyncSqliteSaver.aput fails the same way at aio.py:534.

Description

Checkpoints written by older LangGraph versions record node output under metadata["writes"]. Those values are whatever the node returned — for a chat graph, message objects. The SQLite metadata column is JSON, and put() serializes with a plain json.dumps, so writing such a checkpoint back raises and the write is lost. This is the same bug as #5769, which was reported against PostgresSaver. #6236 fixed it by adding get_serializable_checkpoint_metadata() to LangGraph.checkpoint.base — it wraps get_checkpoint_metadata() and pops writes — and pointing the Postgres savers at it. The SQLite savers were not updated and still call get_checkpoint_metadata():

call site helper
checkpoint-postgres/.../postgres/__init__.py:342 get_serializable_checkpoint_metadata
checkpoint-postgres/.../postgres/aio.py:302 get_serializable_checkpoint_metadata
checkpoint-postgres/.../postgres/shallow.py:447, :785

内容来源: langchain-ai/langgraph