[Django] #24803: Collected SQL does not respect empty strings as params when formatting result sql

Skip to first unread message

Django

unread,
May 14, 2015, 11:27:46 AM5/14/15
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql
----------------------------------------------+--------------------
Reporter: coldmind | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
See https://code.djangoproject.com/ticket/23405#comment:27

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.

Django

unread,
May 14, 2015, 11:39:14 AM5/14/15
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql
-------------------------------------+-------------------------------------

Reporter: coldmind | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by coldmind):

* 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>

Django

unread,
May 14, 2015, 11:44:52 AM5/14/15
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql
-------------------------------------+-------------------------------------

Reporter: coldmind | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 14, 2015, 11:50:20 AM5/14/15
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql
-------------------------------------+-------------------------------------

Reporter: coldmind | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 14, 2015, 12:10:20 PM5/14/15
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql on MySQL
-------------------------------------+-------------------------------------

Reporter: coldmind | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:4>

Django

unread,
May 14, 2015, 12:31:50 PM5/14/15
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql
-------------------------------------+-------------------------------------

Reporter: coldmind | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 14, 2015, 8:13:08 PM5/14/15
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql
-------------------------------------+-------------------------------------

Reporter: coldmind | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:6>

Django

unread,
Jul 26, 2015, 3:48:01 AM7/26/15
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql
-------------------------------------+-------------------------------------

Reporter: coldmind | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JMGordon):

* cc: JMGordon (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:7>

Django

unread,
Dec 31, 2021, 5:33:20 AM12/31/21
to django-...@googlegroups.com
#24803: Collected SQL does not respect empty strings as params when formatting
result sql
-------------------------------------+-------------------------------------
Reporter: Andriy Sokolovskiy | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #25705.

--
Ticket URL: <https://code.djangoproject.com/ticket/24803#comment:8>

Reply all
Reply to author
Forward
0 new messages