You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to create a diamond inheritance structure using a class that inherits from a Mongo Document fails. The simplest example is just:
from mongoengine import Document
class A(Document):
meta = {'allow_inheritance': True}
class B(A):
pass
class C(A):
pass
class D(B,C):
pass
This results an error while constructing the Bat class: TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution order (MRO) for bases DoesNotExist, DoesNotExist in metaclasses.pyc.
This more elaborate example should demonstrate what I wish to accomplish (and why a mixin approach wouldn't work). I intend to use each of these types in ReferenceFields, which require the classes to inherit Document.
from mongoengine import Document, fields
class Animal(Document):
meta = {'allow_inheritance': True, 'collection': 'animals'}
id = fields.UUIDField(primary_key=True, required=True)
food = fields.StringField(required=True)
class Mammal(Animal):
breathing_rate = fields.FloatField(required=True)
class WingedAnimal(Animal):
wing_span = fields.FloatField(required=True)
class Bat(Mammal, WingedAnimal):
pass
class Anthropologist(Document):
favourite_mammal = fields.ReferenceField(Mammal, dbref=True)
favourite_winged = fields.ReferenceField(WingedAnimal, dbref=True)
The text was updated successfully, but these errors were encountered:
alainbryden
changed the title
Method Resolution Order (MRO) when Document involved in diamond inheritance.
Method resolution order (MRO) error when Document is involved in diamond inheritance.
Nov 20, 2014
Trying to create a diamond inheritance structure using a class that inherits from a Mongo Document fails. The simplest example is just:
This results an error while constructing the
Bat
class:TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution order (MRO) for bases DoesNotExist, DoesNotExist
inmetaclasses.pyc
.This more elaborate example should demonstrate what I wish to accomplish (and why a mixin approach wouldn't work). I intend to use each of these types in ReferenceFields, which require the classes to inherit Document.
The text was updated successfully, but these errors were encountered: