[Sqlalchemy-tickets] Issue #3804: "Invalid utf8 character string" warning on insert into binary-typ
Brought to you by:
zzzeek
From: Andrew M. <iss...@bi...> - 2016-09-22 23:07:21
|
New issue 3804: "Invalid utf8 character string" warning on insert into binary-type columns with MySQL 5.6 https://bitbucket.org/zzzeek/sqlalchemy/issues/3804/invalid-utf8-character-string-warning-on Andrew Mason: I have encountered this issue trying to insert a binary UUID (i.e. uuid.uuid4().bytes) into both varbinary(16). I have also encountered this issue trying to insert binary data into a mediumblob column, so I suspect the issue is affecting all binary-type columns. Note that MySQL 5.5 happily executes the insert, but MySQL 5.6 (and likely later versions) spew warnings. This django user has submitted an issue against MySQL [here](https://bugs.mysql.com/bug.php?id=79317). The purported solution is instead of doing ``` #!sql INSERT INTO `user` (uuid) VALUES (%s) ``` to do ``` #!sql INSERT INTO `user` (uuid) VALUES (_binary %s) ``` which will cause MySQL to treat the data as binary rather than utf8-encoded data. The problem here is that MySQL is trying to validate the value being populated as utf8, and if it's not valid utf8, is throwing the warning. One might argue that this doesn't need to be done, since it's populating a binary column type, but since we're passing a string (and not casting it as a _binary), MySQL stands by it's warning. I am using the python mysqldb for my DBAPI, SQLAlchemy 1.0.12, and (attempting to, at least, as noted above) MySQL 5.6. Attached is a traceback where the issue occurs. |