Finally had some time to check again. I initially noticed this issue with 
Django 1.7 + MySQL, but I retested with the latest version of Django:

Django==1.10.5 (latest version from pip)
MySQL-python==1.2.5

On Python2.7.13 with MySQL 5.7.10 (installed via homebrew). I also tried 
mysqlclient (1.3.9), same issue. I dug into the Django source, and I see 
the value going through quote_value 
here: 
https://github.com/django/django/blob/master/django/db/backends/mysql/schema.py#L30

I believe I found the issue:
>>> import MySQLdb.converters
>>> print MySQLdb.escape('a b c d', MySQLdb.converters.conversions)
'a b c d'
>>> print MySQLdb.escape(u'a b c d', MySQLdb.converters.conversions)
a b c d

Inside quote_value, Django passes a unicode object for the value arg, and 
MySQLdb 
fails to quote it properly. With this, it appears to be a bug with 
mysql-python itself, or my mysql version?


On Friday, February 3, 2017 at 1:14:14 PM UTC-8, Markus Holtermann wrote:
>
> I gave it a quick look, but I can't reproduce this issue on the current 
> master branch for SQLite3, PostgreSQL or MySQL. Can you give us more 
> information when you report the issue please, such as Django version, 
> database + version, database driver + version, and anything you think might 
> be helpful. Thank you
>
> /Markus
>
> On Friday, February 3, 2017 at 7:27:31 PM UTC+1, Michael Grijalva wrote:
>>
>> Ok thank you. I will dig into it more.
>>
>> On Thursday, February 2, 2017 at 7:57:16 AM UTC-8, Tim Graham wrote:
>>>
>>> It looks like a bug at first glance. I encourage you to look at Django's 
>>> source code and try to confirm and fix it.
>>>
>>> On Wednesday, February 1, 2017 at 8:11:21 PM UTC-5, Michael Grijalva 
>>> wrote:
>>>>
>>>> Not sure if this is considered a bug, but the SQL output from 
>>>> sqlmigrate contains a small syntax error with default string values:
>>>>
>>>> Add a new column as so:
>>>> class City(models.Model):
>>>>     ...
>>>>     name = models.CharField(max_length=100, default='a b c d')
>>>>
>>>> Create migration, and run sqlmigrate command:
>>>> BEGIN;
>>>> --
>>>> -- Add field name to city
>>>> --
>>>> ALTER TABLE `map_city` ADD COLUMN `name ` varchar(100) DEFAULT a b c d 
>>>> NOT NULL;
>>>> ALTER TABLE `map_city` ALTER COLUMN `name ` DROP DEFAULT;
>>>> COMMIT;
>>>>
>>>> Notice 'a b c d' is missing quotes. When this migration is actually 
>>>> applied it runs through cursor.execute, which properly quotes the value.
>>>>
>>>> I realize sqlmigrate is only for getting a preview of the SQL, but 
>>>> other parts like the table name and columns are correctly quoted, so why 
>>>> not the default?
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f1e91670-f627-4157-bd20-f02715d0af97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to