Opened 8 years ago

Closed 8 years ago

#27935 closed Bug (fixed)

BrinIndex crashes if name > 30 characters

Reported by: Den Owned by: Tim Graham <timograham@…>
Component: contrib.postgres Version: 1.11
Severity: Release blocker Keywords:
Cc: felisiak.mariusz@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

BrinIndex.suffix ( django.contrib.postgres.indexes) longer 3 char, but Index.set_name_with_model method allowed 3 char in suffix

AssertionError: Index too long for multiple database support. Is self.suffix longer than 3 characters?

Change History (11)

comment:1 by Markus Holtermann, 8 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

There are no tests for auto-generated index names as there are for GinIndex: https://github.com/django/django/blob/master/tests/postgres_tests/test_indexes.py#L61-L64

comment:2 by Mariusz Felisiak, 8 years ago

Cc: felisiak.mariusz@… added

comment:3 by Mads Jensen, 8 years ago

The current model wasn't actually enough to trigger a failure for the auto-generated name as the length of the indexed field is only 5 characters.

Either changing suffix = brin to suffix = brn, or removing a character from the hash so it's just five characters. Probably the first is better?

def test_name_auto_generation_fail(self):
    # name of field must be at least 7 characters long to get to 30 characters
    index = BrinIndex(fields=['datetimes'])
    index.set_name_with_model(DateTimeArrayModel)
    self.assertEqual(index.name, 'postgres_te_datetim_b1e2ca_brn')

Last edited 8 years ago by Mads Jensen (previous) (diff)

comment:4 by Mads Jensen, 8 years ago

Has patch: set

comment:5 by Tim Graham, 8 years ago

Summary: BrinIndex.suffix for postgres longer 3 charBrinIndex crashes if name > 30 characters
Triage Stage: AcceptedReady for checkin

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

Owner: set to Tim Graham <timograham@…>
Resolution: fixed
Status: newclosed

In 82bb4e68:

Fixed #27935 -- Fixed crash with BrinIndex name > 30 characters.

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

In 0b93a992:

[1.11.x] Fixed #27935 -- Fixed crash with BrinIndex name > 30 characters.

Backport of 82bb4e684f9d0e5939cb0596c249954df0888e2d from master

comment:8 by Tim Graham, 8 years ago

Has patch: unset
Resolution: fixed
Status: closednew
Triage Stage: Ready for checkinAccepted

Florian pointed out on IRC that in a mixed database setup, connection.ops.max_name_length() won't necessarily be a PostgreSQL connection. Maybe that could use the db.backends.postgresql.operations.DatabaseOperations class instead.

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

In 2867b7eb:

Refs #27935 -- Fixed BrinIndex.max_name_length if a project's default database isn't PostgreSQL.

Thanks Florian Apolloner for the report.

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

In 40b84348:

[1.11.x] Refs #27935 -- Fixed BrinIndex.max_name_length if a project's default database isn't PostgreSQL.

Thanks Florian Apolloner for the report.

Backport of 2867b7eb4b8477710f11707d4b975db10e5f91a7 from master

comment:11 by Tim Graham, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top