#26139: Django's UUID inserted into MySQL => Warning
--------------------------------+--------------------
     Reporter:  guilhem-bichot  |      Owner:  nobody
         Type:  Uncategorized   |     Status:  new
    Component:  Uncategorized   |    Version:  1.9
     Severity:  Normal          |   Keywords:
 Triage Stage:  Unreviewed      |  Has patch:  0
Easy pickings:  0               |      UI/UX:  0
--------------------------------+--------------------
 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]

--
Ticket URL: <https://code.djangoproject.com/ticket/26139>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/057.e990da8dafeb29cbad47076a94686430%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to