Opened 15 years ago
Closed 15 years ago
#13460 closed (duplicate)
django.db.models.Model breaks multiple inheritance
Reported by: | Art | 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: | no | UI/UX: | no |
Description
django.db.models.Model breaks multiple inheritance by not calling
super(...).init(...)
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' D()
Resulting in:
A D
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:
C B A D
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 http://fuhm.net/super-harmful/ for more details.
Note:
See TracTickets
for help on using tickets.
Duplicate of #13206.