#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:1 by , 8 years ago
| Has patch: | set |
|---|
comment:2 by , 8 years ago
| Triage Stage: | Unreviewed → Ready for checkin |
|---|
comment:3 by , 8 years ago
| Summary: | Index names can be inapropriately truncated when using a namespaced table name → Index names can be incorrectly truncated when using a namespaced table name |
|---|
https://github.com/django/django/pull/9345