[Django] #30145: SQLCompiler do not escape names correctly

7 views
Skip to first unread message

Django

unread,
Jan 30, 2019, 12:31:27 PM1/30/19
to django-...@googlegroups.com
#30145: SQLCompiler do not escape names correctly
-------------------------------------+-------------------------------------
Reporter: Artem | Owner: nobody
Skoretskiy |
Type: Bug | Status: new
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I generate custom SQL and I have tried to use `SQLCompiler` to escape
(quote) table names. But it does not work as expected:

{{{
>>> from django.contrib.auth.models import User
>>> qs = User.objects.all()
>>> compiler = qs.query.get_compiler(using=qs.db)
>>> name = 'b"; drop table "world'
>>> sql = 'alter table x rename column a to
{};'.format(compiler.quote_name_unless_alias(name))
>>> print(sql)
alter table x rename column a to "b"; drop table "world";
}}}

I would expect that it would return name that I could use in raw SQL.

You could try youself:

{{{
docker run -ti --rm python:3.7-alpine sh -c "pip install -q
https://github.com/django/django/archive/master.zip && django-admin.py
startproject project . && ./manage.py shell"
}}}

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

Django

unread,
Jan 30, 2019, 1:07:47 PM1/30/19
to django-...@googlegroups.com
#30145: SQLCompiler do not escape names correctly
-------------------------------------+-------------------------------------
Reporter: Artem Skoretskiy | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: invalid
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 Tim Graham):

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


Comment:

`SQLCompiler` isn't a public API. Any usage is at your own risk.

--
Ticket URL: <https://code.djangoproject.com/ticket/30145#comment:1>

Reply all
Reply to author
Forward
0 new messages