From 807bc7ade1d3b5bc8e17dbf659de25351363419f Mon Sep 17 00:00:00 2001 From: Thomas_Tan Date: Thu, 27 Feb 2025 10:42:26 +0800 Subject: [PATCH 1/3] fix: sql replace concat --- pymysql/connections.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pymysql/connections.py b/pymysql/connections.py index 99fcfcd0..6a1fd04f 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -570,6 +570,8 @@ def query(self, sql, unbuffered=False): # if DEBUG: # print("DEBUG: sending query:", sql) if isinstance(sql, str): + sql = sql.replace("json_extract(checkpoint, concat('$.channel_versions.', channel))", + """json_extract(checkpoint, concat('$.channel_versions."', channel, '"'))""") sql = sql.encode(self.encoding, "surrogateescape") self._execute_command(COMMAND.COM_QUERY, sql) self._affected_rows = self._read_query_result(unbuffered=unbuffered) From 74c85e301a91c2a7224962ea30b7ea343a0c27dc Mon Sep 17 00:00:00 2001 From: Thomas_Tan Date: Thu, 27 Feb 2025 10:42:36 +0800 Subject: [PATCH 2/3] notes: reason and fix --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 95e4520a..02ab2517 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ [![Documentation Status](https://readthedocs.org/projects/pymysql/badge/?version=latest)](https://pymysql.readthedocs.io/) [![codecov](https://codecov.io/gh/PyMySQL/PyMySQL/branch/main/graph/badge.svg?token=ppEuaNXBW4)](https://codecov.io/gh/PyMySQL/PyMySQL) +# PyMySQL - Riversoft version +This fork is to solve the MySQL `connections.py` line 573 SQL query error. We faced this bug when using `langgraph` and specifically `langgraph-checkpoint-mysql` that has "start:something" as its value, thus the ":" crashes the original SQL call. + +The following is the original repo README. + # PyMySQL This package contains a pure-Python MySQL and MariaDB client library, based on From 96195f4e4ad62ed592a30ea793de1467ceb8f9b0 Mon Sep 17 00:00:00 2001 From: Thomas_Tan Date: Thu, 27 Feb 2025 10:56:22 +0800 Subject: [PATCH 3/3] fix: wrong double quote position --- pymysql/connections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index 6a1fd04f..1b81e617 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -571,7 +571,7 @@ def query(self, sql, unbuffered=False): # print("DEBUG: sending query:", sql) if isinstance(sql, str): sql = sql.replace("json_extract(checkpoint, concat('$.channel_versions.', channel))", - """json_extract(checkpoint, concat('$.channel_versions."', channel, '"'))""") + """json_extract(checkpoint, concat('$."channel_versions.', channel, '"'))""") sql = sql.encode(self.encoding, "surrogateescape") self._execute_command(COMMAND.COM_QUERY, sql) self._affected_rows = self._read_query_result(unbuffered=unbuffered)