Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method resolution order (MRO) error when Document is involved in diamond inheritance. #808

Closed
alainbryden opened this issue Nov 20, 2014 · 0 comments

Comments

@alainbryden
Copy link

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)
@alainbryden 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant