Opened 11 years ago

Closed 11 years ago

#22740 closed Bug (wontfix)

Model gets Meta from abstract ancestor class in MTI

Reported by: German M. Bravo Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords:
Cc: anubhav9042@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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:

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.

Attachments (1)

#22740-abstract_concrete_multitable.diff (398 bytes ) - added by German M. Bravo 11 years ago.

Download all attachments as: .zip

Change History (4)

by German M. Bravo, 11 years ago

comment:1 by ANUBHAV JOSHI, 11 years ago

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.

comment:2 by ANUBHAV JOSHI, 11 years ago

Cc: anubhav9042@… added
Component: UncategorizedDatabase layer (models, ORM)
Summary: Multi-table inheritance gets Meta from abstract ancestor model classModel gets Meta from abstract ancestor class in MTI
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

I am marking it as accepted.

comment:3 by Aymeric Augustin, 11 years ago

Resolution: wontfix
Status: newclosed

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.

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