Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#28792 closed Bug (fixed)

Index names can be incorrectly truncated when using a namespaced table name

Reported by: Simon Charette Owned by: Simon Charette
Component: Migrations Version: 1.11
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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:

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.

Change History (8)

comment:2 by Tim Graham, 6 years ago

Triage Stage: UnreviewedReady for checkin

comment:3 by Tim Graham, 6 years ago

Summary: Index names can be inapropriately truncated when using a namespaced table nameIndex names can be incorrectly truncated when using a namespaced table name

comment:4 by Simon Charette <charette.s@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In ee85ef8:

Fixed #28792 -- Fixed index name truncation of namespaced tables.

Refs #27458, #27843.

Thanks Tim and Mariusz for the review.

comment:5 by Simon Charette <charette.s@…>, 6 years ago

In a35ab95e:

[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

comment:6 by Claude Paroz, 6 years ago

Simon, master and 1.11, but not 2.0?

comment:7 by Tim Graham <timograham@…>, 6 years ago

In 0696edbc:

[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

comment:8 by Simon Charette, 6 years ago

Thanks Tim, completely forgot about 2.0.

Note: See TracTickets for help on using tickets.
Back to Top