Skip to content

INSERT into json column on MySQL 8 with binary_prefix fails (succeeds for pymysql) #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zzzeek opened this issue Apr 27, 2021 · 0 comments · Fixed by #605
Closed

INSERT into json column on MySQL 8 with binary_prefix fails (succeeds for pymysql) #494

zzzeek opened this issue Apr 27, 2021 · 0 comments · Fixed by #605

Comments

@zzzeek
Copy link

zzzeek commented Apr 27, 2021

hey there -

one of my users found this, there's no pressure at all for this to be fixed if it's not possible, I just wanted to get it logged as a known issue in case other people hit it as I did not see it here. Using the "binary_prefix" feature with mysqlclient on MySQL 8 seems to break JSON values with MySQLdb._exceptions.OperationalError: (3144, "Cannot create a JSON value from a string with CHARACTER SET 'binary'."), example below which compares the same operation succeeding with pymysql.

MySQL version: Server version: 8.0.21 MySQL Community Server - GPL
MySQLClient: 2.0.3final0

reproduction:

import MySQLdb
import pymysql


def test(dbapi):
    conn = dbapi.connect(
        user="scott",
        password="tiger",
        host="mysql80",
        db="test",
        binary_prefix=True,
    )


    cursor = conn.cursor()

    cursor.execute("DROP TABLE IF EXISTS test")
    cursor.execute(
        """
CREATE TABLE test (
	id INTEGER NOT NULL AUTO_INCREMENT,
	json JSON NOT NULL,
	PRIMARY KEY (id)
)CHARSET=utf8
    """
    )

    cursor.executemany(
        "INSERT INTO test (id, json) VALUES (%(id)s, %(json)s)",
        ({"id": 1, "json": "{}"}, {"id": 2, "json": "{}"}),
    )

    conn.rollback()

test(pymysql)  # succeeds

# MySQLdb._exceptions.OperationalError: (3144, "Cannot create a JSON value from a string with CHARACTER SET 'binary'.")
test(MySQLdb)  # fails

have a nice day!

@methane methane modified the milestones: v2.0, v2.2 Oct 19, 2021
@methane methane removed this from the v2.2 milestone May 9, 2023
methane added a commit to methane/mysqlclient that referenced this issue May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants