Skip to content

Commit

Permalink
Better fix for collation error in select query.
Browse files Browse the repository at this point in the history
Instead of sending a SET NAMES query when creating the connection, do a
conversion of the column value returned from the JSON_TABLE call to the
utf8mb4 character set using its default collation. For some reason, this
is necessary or else that column ends up with a different collation.
  • Loading branch information
tjni committed Jan 14, 2025
1 parent 4889b13 commit 8d30a85
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 18 deletions.
10 changes: 0 additions & 10 deletions langgraph/checkpoint/mysql/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from typing import Any, Optional, cast

import aiomysql # type: ignore
import pymysql
import pymysql.connections
from langchain_core.runnables import RunnableConfig
from typing_extensions import Self, override

Expand Down Expand Up @@ -87,10 +85,6 @@ async def from_conn_string(
**cls.parse_conn_string(conn_string),
autocommit=True,
) as conn:
# This seems necessary until https://github.com/PyMySQL/PyMySQL/pull/1119
# is merged into aiomysql.
await conn.set_charset(pymysql.connections.DEFAULT_CHARSET)

yield cls(conn=conn, serde=serde)

async def setup(self) -> None:
Expand Down Expand Up @@ -494,10 +488,6 @@ async def from_conn_string(
**AIOMySQLSaver.parse_conn_string(conn_string),
autocommit=True,
) as conn:
# This seems necessary until https://github.com/PyMySQL/PyMySQL/pull/1119
# is merged into aiomysql.
await conn.set_charset(pymysql.connections.DEFAULT_CHARSET)

yield cls(conn=conn, serde=serde)

@override
Expand Down
2 changes: 1 addition & 1 deletion langgraph/checkpoint/mysql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
) as version
from json_table(
json_keys(checkpoint, '$.channel_versions'),
'$[*]' columns (channel VARCHAR(150) PATH '$')
'$[*]' columns (channel VARCHAR(150) CHARACTER SET utf8mb4 PATH '$')
) as channels
) as channel_versions
inner join checkpoint_blobs bl
Expand Down
2 changes: 1 addition & 1 deletion langgraph/checkpoint/mysql/shallow.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
select json_arrayagg(json_array(bl.channel, bl.type, bl.blob))
from json_table(
json_keys(checkpoint, '$.channel_versions'),
'$[*]' columns (channel VARCHAR(150) PATH '$')
'$[*]' columns (channel VARCHAR(150) CHARACTER SET utf8mb4 PATH '$')
) as channels
inner join checkpoint_blobs bl
on bl.channel = channels.channel
Expand Down
5 changes: 0 additions & 5 deletions langgraph/store/mysql/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import aiomysql # type: ignore
import orjson
import pymysql

from langgraph.checkpoint.mysql import _ainternal
from langgraph.store.base import (
Expand Down Expand Up @@ -93,10 +92,6 @@ async def from_conn_string(
**cls.parse_conn_string(conn_string),
autocommit=True,
) as conn:
# This seems necessary until https://github.com/PyMySQL/PyMySQL/pull/1119
# is merged into aiomysql.
await conn.set_charset(pymysql.connections.DEFAULT_CHARSET)

yield cls(conn=conn)

async def setup(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langgraph-checkpoint-mysql"
version = "2.0.10"
version = "2.0.11"
description = "Library with a MySQL implementation of LangGraph checkpoint saver."
authors = ["Theodore Ni <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 8d30a85

Please sign in to comment.