Skip to content

DynamicDocument issue for Document with inheritance #1054

@bagerard

Description

@bagerard

Hi There,
I had an issue today while using DynamicDocument on a collection that makes use of some inheritance.
Note that using .exclude('_cls') is solving my problem but I thought it could be good to let you know.
Below is a reproducible scenario. BTW mongoengine is awesome, thanks for the hard work!

class Geek(Document):
    meta = {'allow_inheritance': True}
    name = StringField()

class AwesomeGeek(Geek):
    has_laptop = BooleanField()

gk = AwesomeGeek(name='John', has_laptop=True).save()

class DynamicGeek(DynamicDocument):
    meta = {'collection': 'geek'}


DynamicGeek.objects.first()   # raises mongoengine.errors.FieldDoesNotExist
                                                 #The field 'has_laptop' does not exist on the document
                                                 # Geek.AwesomeGeek
DynamicGeek.objects.exclude('_cls').first()    # works great

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions