Opened 6 years ago

Closed 6 years ago

#13460 closed (duplicate)

django.db.models.Model breaks multiple inheritance

Reported by: Art_S Owned by: nobody
Component: Core (Other) Version: 1.1
Severity: Keywords: inheritance
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


django.db.models.Model breaks multiple inheritance by not calling


Here's example code:

from django.db import models

class A(models.Model):
    def __init__(self, *args, **kwargs):
        super(A, self).__init__(*args, **kwargs)
        print 'A'

    m = models.CharField()

class B(object):
    def __init__(self, *args, **kwargs):
        super(B, self).__init__(*args, **kwargs)
        print 'B'

class C(object):
    def __init__(self, *args, **kwargs):
        super(C, self).__init__(*args, **kwargs)
        print 'C'

class D(A, B, C):
    def __init__(self, *args, **kwargs):
        super(D, self).__init__(*args, **kwargs)
        print 'D'


Resulting in:


However as soon as I remove models.Model from parent for A and replace it with 'object', all the constructors are getting called and the output is:


Apparently this happens because MRO is nto beign composed properly when you ommit calls to parent's init, even if it's the object.
See for more details.

Change History (1)

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #13206.

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