[FIX] models: reorder the base classes of models following an equivalent class hierarchy
Sometimes, the expected mro of the model is not the same as the one built with a binary class hierarchy. So we reorder the base classes in order to match the equivalent binary class hierarchy. This also fixes the cases where duplicates appear in base classes.
This commit is contained in:
parent
9bce04de79
commit
bf703fd9a3
|
@ -603,11 +603,17 @@ class BaseModel(object):
|
||||||
|
|
||||||
# determine all the classes the model should inherit from
|
# determine all the classes the model should inherit from
|
||||||
bases = [cls]
|
bases = [cls]
|
||||||
|
hierarchy = cls
|
||||||
for parent in parents:
|
for parent in parents:
|
||||||
if parent not in pool:
|
if parent not in pool:
|
||||||
raise TypeError('The model "%s" specifies an unexisting parent class "%s"\n'
|
raise TypeError('The model "%s" specifies an unexisting parent class "%s"\n'
|
||||||
'You may need to add a dependency on the parent class\' module.' % (name, parent))
|
'You may need to add a dependency on the parent class\' module.' % (name, parent))
|
||||||
bases += type(pool[parent]).__bases__
|
parent_class = type(pool[parent])
|
||||||
|
bases += parent_class.__bases__
|
||||||
|
hierarchy = type(name, (hierarchy, parent_class), {'_register': False})
|
||||||
|
|
||||||
|
# order bases following the mro of class hierarchy
|
||||||
|
bases = [base for base in hierarchy.mro() if base in bases]
|
||||||
|
|
||||||
# determine the attributes of the model's class
|
# determine the attributes of the model's class
|
||||||
inherits = {}
|
inherits = {}
|
||||||
|
|
Loading…
Reference in New Issue