Skip to content

Filtering on embedded attribute raises an exception (regression 0.9/0.10) #1066

@bagerard

Description

@bagerard

Hi There,
I observed a regression after switching to 0.10.0 when querying objects on embedded attribute. It raises an AttributeError as soon as you iterate or .count

Below is a test case:

class MyEmbeddedClass(EmbeddedDocument):
    name = StringField()

class MyClass(Document):
    emb_attr = EmbeddedDocumentField(MyEmbeddedClass, default=None)

MyClass(emb_attr=MyEmbeddedClass(name='bob')).save()

MyClass.objects(emb_attr=None).count()

And the end of the stack trace:
(...)
File ".../mongoengine/queryset/transform.py", line 95, in query
value = field.prepare_query_value(op, value)
File ".../mongoengine/fields.py", line 570, in prepare_query_value
value = self.document_type._from_son(value)
File ".../mongoengine/base/document.py", line 687, in _from_son
class_name = son.get('_cls', cls._class_name)
AttributeError: 'NoneType' object has no attribute 'get'

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