Opened 9 years ago

Closed 8 years ago

#24442 closed Bug (fixed)

Index name truncation is odd

Reported by: Shai Berger Owned by: Akshesh Doshi
Component: Migrations Version: dev
Severity: Normal Keywords: oracle
Cc: Markus Holtermann Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The code that generates index names for migrations (https://github.com/django/django/blob/8ca35d7c6a639933927f45b439363a1614da56f1/django/db/backends/base/schema.py#L789) behaves in undesired ways when the name it has created turns out to be too long. It starts by cutting out parts of the table name (with no compensation hash), which could lead to name-uniqueness violations; and in case this wasn't enough, just gives up on meaningful naming and replaces the whole name with a digest.

We should do better. Here's one suggestion: divide the available name length into 3 equal parts -- one for the table name, one for the first column name, and one for the uniqueness-digest and suffix. Make each part fit its size by the normal truncation method, replacing its end with a 4-hexdigit hash if necessary.

I'm tempted to mark this a blocker -- so that we don't end up with incorrectly named indexes in the wild.

Change History (4)

comment:1 by Markus Holtermann, 9 years ago

Cc: Markus Holtermann added

comment:2 by Akshesh Doshi, 8 years ago

Owner: changed from nobody to Akshesh Doshi
Status: newassigned

comment:4 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 324c1b43:

Fixed #24442 -- Improved SchemaEditor's index name truncation.

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