﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26139	"UUIDField value must be declared ""binary"" to avoid MySQL warning"	Guilhem Bichot	nobody	"I'm a developer of the MySQL DBMS at Oracle.
A user of Django (Giovanni Go) reported this:
http://bugs.mysql.com/bug.php?id=79317
He writes
""We use UUID stored as binary(16) PK to identify users.
We're seeing an issue where MySQL is trying to validate binary as UTF8 
starting with MySQL 5.6.27 when trying to insert (and presumingly 
select) users. It will insert the row, but since Django treats MySQL 
warnings as exception, Django will bail out.
Setup: Python 2.7, Django 1.6.6, MySQL-python 1.2.5, Ubuntu 14.04/OSX
Django will treat any MySQL warnings as exception if you have DEBUG 
turned on.""

Then he gives a simple Python, Django-less program to show the issue.

I don't have a Django installation, but the problem is apparently that:
- Django generates a UUID object per the user's request
- it inserts it into a MySQL table column, with a simple INSERT:
INSERT INTO table (column) VALUES('cryptic chars here');
those can be really cryptic as a UUID string is made of any bytes from 
0x00 to 0xFF.
- MySQL expects the string to be valid utf8; it has expected this for 
years, but only recently did it start warning when the string is not 
valid utf8 (this is the relevant change:
https://github.com/mysql/mysql-server/commit/33a2e5abd ).
- In fact, the string is not valid utf8: certain sequences of bytes do 
not match utf8 characters. The string is binary. Then it would make 
sense for the client to declare it; which is done this way:
INSERT INTO table (column) VALUES(_binary 'cryptic chars here');
The _binary prefix says ""what I'm giving you next is binary"":
http://dev.mysql.com/doc/refman/5.7/en/charset-literal.html .
Another option would be to use the x'' syntax in the INSERT:
https://dev.mysql.com/doc/refman/5.7/en/hexadecimal-literals.html .
INSERT INTO table (column) VALUES(x'hex codes of cryptic chars here');

Is there any chance to modify Django's code to address this issue?

In the report, please ignore any comments starting from ""[25 Jan 2:14] "	Bug	closed	Database layer (models, ORM)	1.9	Normal	invalid	MySQL		Accepted	0	0	0	0	0	0
