[Django] #28792: Index names can be inapropriately truncated when using a namespaced table name

22 views
Skip to first unread message

Django

unread,
Nov 11, 2017, 8:57:07 PM11/11/17
to django-...@googlegroups.com
#28792: Index names can be inapropriately truncated when using a namespaced table
name
-------------------------------------+-------------------------------------
Reporter: Simon | Owner: Simon Charette
Charette |
Type: Bug | Status: assigned
Component: | Version: 1.11
Migrations |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When using a namespaced `_meta.db_table` (e.g. Oracle's
`'schema"."table'`) it's possible that `_create_index_name` returns an
index name truncating the namespace resulting in an invalid identifier or
one that isn't namespaced anymore and thus created in the user's
namespace.

For example, given the following model:

{{{#!python
class Foo(models.Model):
field = models.IntegerField(index=True)

class Meta:
db_table = 'long_name"."table_name'
}}}

The resulting index name will be `'long_name"_field_d21c9e0a'` which is
invalid SQL even when quoted to `'"long_name"_field_d21c9e0a"'`.

Marking as a release blocker because this is a regression which I believe
was introduced by #27458 and wasn't addressed by #27843. I confirm that
this uses to work on Django 1.10 but was broken on 1.11 as I stumbled upon
the issue when upgrading a Django 1.8 LTS codebase to 1.11 LTS on the 1.10
-> 1.11 step.

The tests added by #27458 just happened to work because the index name
truncation cut the string the in a way that both double quotes are
stripped. It should be possible to tweak the table names to trigger the
errors but I felt like directly testing `_create_index_name` was more
appropriate.

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

Django

unread,
Nov 11, 2017, 8:59:50 PM11/11/17
to django-...@googlegroups.com
#28792: Index names can be inapropriately truncated when using a namespaced table
name
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon

| Charette
Type: Bug | Status: assigned
Component: Migrations | Version: 1.11
Severity: Release blocker | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/9345

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

Django

unread,
Nov 14, 2017, 2:30:46 PM11/14/17
to django-...@googlegroups.com
#28792: Index names can be inapropriately truncated when using a namespaced table
name
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon

| Charette
Type: Bug | Status: assigned
Component: Migrations | Version: 1.11
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28792#comment:2>

Django

unread,
Nov 14, 2017, 2:38:58 PM11/14/17
to django-...@googlegroups.com
#28792: Index names can be incorrectly truncated when using a namespaced table name
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon

| Charette
Type: Bug | Status: assigned
Component: Migrations | Version: 1.11
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/28792#comment:3>

Django

unread,
Nov 14, 2017, 9:53:50 PM11/14/17
to django-...@googlegroups.com
#28792: Index names can be incorrectly truncated when using a namespaced table name
-------------------------------------+-------------------------------------

Reporter: Simon Charette | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: 1.11
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette <charette.s@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ee85ef8315db839e5723dea19d8b971420a2ebb4" ee85ef8]:
{{{
#!CommitTicketReference repository=""
revision="ee85ef8315db839e5723dea19d8b971420a2ebb4"
Fixed #28792 -- Fixed index name truncation of namespaced tables.

Refs #27458, #27843.

Thanks Tim and Mariusz for the review.
}}}

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

Django

unread,
Nov 14, 2017, 10:07:31 PM11/14/17
to django-...@googlegroups.com
#28792: Index names can be incorrectly truncated when using a namespaced table name
-------------------------------------+-------------------------------------

Reporter: Simon Charette | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: 1.11
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette <charette.s@…>):

In [changeset:"a35ab95ed4eec5c62fa19bdc69ecfe0eff3e1fca" a35ab95e]:
{{{
#!CommitTicketReference repository=""
revision="a35ab95ed4eec5c62fa19bdc69ecfe0eff3e1fca"
[1.11.x] Fixed #28792 -- Fixed index name truncation of namespaced tables.

Refs #27458, #27843.

Thanks Tim and Mariusz for the review.

Backport of ee85ef8315db839e5723dea19d8b971420a2ebb4 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28792#comment:5>

Django

unread,
Nov 15, 2017, 4:12:26 AM11/15/17
to django-...@googlegroups.com
#28792: Index names can be incorrectly truncated when using a namespaced table name
-------------------------------------+-------------------------------------

Reporter: Simon Charette | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: 1.11
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

Simon, `master` and `1.11`, but not `2.0`?

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

Django

unread,
Nov 15, 2017, 8:32:01 AM11/15/17
to django-...@googlegroups.com
#28792: Index names can be incorrectly truncated when using a namespaced table name
-------------------------------------+-------------------------------------

Reporter: Simon Charette | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: 1.11
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"0696edbc6a724ceaba86a977b6d21e57647cb2ac" 0696edbc]:
{{{
#!CommitTicketReference repository=""
revision="0696edbc6a724ceaba86a977b6d21e57647cb2ac"
[2.0.x] Fixed #28792 -- Fixed index name truncation of namespaced tables.

Refs #27458, #27843.

Thanks Tim and Mariusz for the review.

Backport of ee85ef8315db839e5723dea19d8b971420a2ebb4 from master
}}}

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

Django

unread,
Nov 15, 2017, 9:15:47 AM11/15/17
to django-...@googlegroups.com
#28792: Index names can be incorrectly truncated when using a namespaced table name
-------------------------------------+-------------------------------------

Reporter: Simon Charette | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Migrations | Version: 1.11
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

Thanks Tim, completely forgot about 2.0.

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

Reply all
Reply to author
Forward
0 new messages