[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:
Raphael Collet 2015-03-05 09:42:38 +01:00
parent 9bce04de79
commit bf703fd9a3
1 changed files with 7 additions and 1 deletions

View File

@ -603,11 +603,17 @@ class BaseModel(object):
# determine all the classes the model should inherit from
bases = [cls]
hierarchy = cls
for parent in parents:
if parent not in pool:
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))
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
inherits = {}