Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28282 closed Bug (fixed)

Index.set_name_with_model() not called on models without a base meta class

Reported by: Jon Dufresne Owned by: nobody
Component: Database layer (models, ORM) 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

From https://github.com/django/django/blob/23825b2494a1edb1e02d57dbdc7eca0614cefcc8/django/db/models/base.py#L296-L303

        if base_meta and base_meta.abstract and not abstract:
            new_class._meta.indexes = [copy.deepcopy(idx) for idx in new_class._meta.indexes]
            # Set the name of _meta.indexes. This can't be done in
            # Options.contribute_to_class() because fields haven't been added
            # to the model at that point.
            for index in new_class._meta.indexes:
                if not index.name:
                    index.set_name_with_model(new_class)

I believe the condition should be changed to if (not base_meta or base_meta.abstract) and not abstract:. Or maybe simply if not abstract? As of right now simple classes inheriting from models.Model have base_meta as None and so the indexes aren't named.

Change History (4)

comment:1 by Jon Dufresne, 7 years ago

Has patch: set

comment:2 by Tim Graham, 7 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedReady for checkin

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

Resolution: fixed
Status: newclosed

In 0c3c37a3:

Fixed #28282 -- Fixed class-based indexes name for models that only inherit Model.

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

In ccb8297e:

[1.11.x] Fixed #28282 -- Fixed class-based indexes name for models that only inherit Model.

Backport of 0c3c37a376bac149fe7e7e4b2696f8fb7990e2ab from master

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