[Django] #22740: Multi-table inheritance gets Meta from abstract ancestor model class

29 views
Skip to first unread message

Django

unread,
May 30, 2014, 7:39:32 PM5/30/14
to django-...@googlegroups.com
#22740: Multi-table inheritance gets Meta from abstract ancestor model class
-------------------------------+--------------------
Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I'm getting this validation error:
{{{
CommandError: One or more models did not validate:
places.restaurant: "index_together" refers to name. This is not in the
same model as the index_together statement.
places.restaurant: "index_together" refers to address. This is not in the
same model as the index_together statement.
}}}

From the following models:
{{{#!python
from django.db import models


class AbstractPlace(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)

class Meta:
abstract = True
index_together = (('name', 'address'),)


class Place(AbstractPlace):
pass


class Restaurant(Place):
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
}}}

Seemingly, the concrete model `Place` ends up with the inherited `Meta`
from the abstract parent. After the `Place` model class is created, during
`ModelBase.__new__`), any `Meta` (declared or inherited) should not be
there for concrete classes.

This way, models would never have a `Meta` (unless the modified and
explicitly added Meta, if they're abstract). I added `new_class.Meta =
None` just above `new_class._prepare()` in `ModelBase` and that properly
fixes the issue.

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

Django

unread,
Jun 13, 2014, 4:21:50 AM6/13/14
to django-...@googlegroups.com
#22740: Multi-table inheritance gets Meta from abstract ancestor model class
-------------------------------+--------------------------------------

Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.6
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
-------------------------------+--------------------------------------
Changes (by anubhav9042):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I think that this a issue that must be corrected. To me even the fix seems
good and simple enough. Though you may want to wait until you hear from a
core-dev.

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

Django

unread,
Jun 13, 2014, 4:24:20 AM6/13/14
to django-...@googlegroups.com
#22740: Model gets Meta from abstract ancestor class in MTI
-------------------------------------+-------------------------------------
Reporter: Kronuz | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.6
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by anubhav9042):

* cc: anubhav9042@… (added)
* component: Uncategorized => Database layer (models, ORM)
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

I am marking it as accepted.

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

Django

unread,
Jun 13, 2014, 5:38:34 AM6/13/14
to django-...@googlegroups.com
#22740: Model gets Meta from abstract ancestor class in MTI
-------------------------------------+-------------------------------------
Reporter: Kronuz | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.6
(models, ORM) | Resolution: wontfix

Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

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


Comment:

Your proposal would break code that relies on the currently documented
behaviour: https://docs.djangoproject.com/en/dev/topics/db/models/#meta-
inheritance

We can have a discussion on the django-developers mailing-list about the
advantages and drawbacks of inheriting Meta from abstract parents.

But we can't accept such a backwards-incompatible change without
discussion.

--
Ticket URL: <https://code.djangoproject.com/ticket/22740#comment:3>

Reply all
Reply to author
Forward
0 new messages