When collecting sql
(https://github.com/django/django/blob/master/django/db/backends/base/schema.py#L105),
if param is an empty string (`''`), it is formatting in the wrong way, so
in the result sql there will be nothing (should be `''`).
--
Ticket URL: <https://code.djangoproject.com/ticket/24803>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I think problem is here
https://github.com/django/django/blob/adf5d75af1418b044d7ea335896e75277da06b77/django/db/backends/base/schema.py#L151
--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:1>
Comment (by dukebody):
@coldmind, I've found the following:
{{{
>>> MySQLdb.escape('', MySQLdb.converters.conversions)
"''"
>>> MySQLdb.escape(u'', MySQLdb.converters.conversions)
''
}}}
And the default parameter for `blank=True` `CharFields` is an unicode
string (checked that with pdb, Django 1.7). So is MySQLdb escaping unicode
strings incorrectly, or should the default parameter be a bytestring
instead?
--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:2>
Comment (by coldmind):
@dukebody, I saw this code, it is not using `quote_value` when generating
sql (put pdb break here and you will see).
The problem line is in my first comment (when chaning `%s` to `%r` it
works, but I'm not sure that it is the right way to resolve problem.)
--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:3>
--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:4>
Comment (by dukebody):
@coldmind, I have this issue with MySQL and the MySQL engine doesn't have
`features.requires_literal_defaults=True`, so that code doesn't get
executed. Tested placing a pdb there.
Apparently MySQLdb quotes bytestrings when escaping, but not unicode
strings: http://sourceforge.net/p/mysql-
python/mysqldb-2/ci/7773efbe9b3012da2827b0284c43267cc9a4ecbd/tree/MySQLdb/converters.py
{{{
def unicode_to_sql(value, conv):
"""Convert a unicode object to a string using the default encoding.
This is only used as a placeholder for the real function, which
is connection-dependent."""
assert isinstance(value, unicode)
return value.encode()
}}}
Could the placeholder comment mean that some connection parameters should
convert the unicode string to a bytestring and then quote it?
--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:5>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:6>
* cc: JMGordon (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:7>
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #25705.
--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:8>