[Django] #32393: Indexes of only the first abstract base class are included in the model

16 views
Skip to first unread message

Django

unread,
Jan 29, 2021, 1:18:12 AM1/29/21
to django-...@googlegroups.com
#32393: Indexes of only the first abstract base class are included in the model
-----------------------------------------+------------------------
Reporter: Dmitry Ulupov | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
If model has multiple base abstract models, their {{{ Meta.indexes }}}
declarations are treated differently.

Only indexes from the first class are taken into account.
Indexes of all other base classes are ignored.

Consider this code:

{{{
class ParentA(models.Model):
field_a = models.CharField(max_length=10)

class Meta:
abstract = True


class ParentB(models.Model):
field_b = models.CharField(max_length=10)

class Meta:
abstract = True
indexes = [
models.Index(
fields=["field_b"],
name="ix_%(app_label)s_%(class)s",
),
]


class ChildOf_A_B(ParentA, ParentB):
pass


class ChildOf_B_A(ParentB, ParentA):
pass

}}}

makemigrations in this case produces this:

{{{

./manage.py makemigrations app

Migrations for 'app':
project/app/migrations/0001_initial.py
- Create model ChildOf_A_B
- Create model ChildOf_B_A
- Create index ix_app_childof_b_a on field(s) field_b of model
childof_b_a

}}}

So index on ChildOf_B_A is created, but on ChildOf_A_B is not.
And only difference is the order of declaration of the base classes.

--
Ticket URL: <https://code.djangoproject.com/ticket/32393>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 29, 2021, 2:44:26 AM1/29/21
to django-...@googlegroups.com
#32393: Indexes of only the first abstract base class are included in the model
-------------------------------+--------------------------------------

Reporter: Dmitry Ulupov | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Dmitry Ulupov):

Just finished re-reading the "multiple inheritance" section and this is an
expected behaviour.
First class indeed clobbers all others and indexes declaration is lost.
Solution is not to have such convoluted structure as I have.

--
Ticket URL: <https://code.djangoproject.com/ticket/32393#comment:1>

Django

unread,
Jan 29, 2021, 2:44:36 AM1/29/21
to django-...@googlegroups.com
#32393: Indexes of only the first abstract base class are included in the model
-------------------------------+--------------------------------------

Reporter: Dmitry Ulupov | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Dmitry Ulupov):

* status: new => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/32393#comment:2>

Reply all
Reply to author
Forward
0 new messages