Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoengine python3 Embedded Document has no attribute _is_document

I am creating my a document having a field as EmbeddedDocument using mongoengine.

But I am getting the following error :

AttributeError: 'EmbeddedDocument' object has no attribute '_is_document'

Doing some reasearch I found that the code of mongoengine is written in python 2 and do make it work properly install it using pip3. Did the same still not working.

class DataImportNodeInfo(EmbeddedDocument):

    provider_id = fields.IntField(required=False)
    carrier_name = fields.StringField(required=False)
    basepath = fields.StringField(required=False)
    log_tobe_imported = fields.ListField(required=False)


class DataImportConnectionInfo(EmbeddedDocument):

    host = fields.StringField(required=True)
    user_login = fields.StringField(required=False)
    user_pwd = fields.StringField(required=False)


class DataImportNode(DynamicDocument):

    # Meta variables
    meta = {
    'collection': str(KonnectDAConstants.DATA_IMPORT_NODES)
    }

    cmd = fields.StringField(required=True)
    import_source = fields.StringField(required=True)
    import_type = fields.StringField(required=True)
    active = fields.BooleanField(required=True)
    info = fields.EmbeddedDocument(DataImportNodeInfo, required=True)
    connection = fields.EmbeddedDocument(DataImportConnectionInfo, required=True)

AttributeError: 'EmbeddedDocument' object has no attribute '_is_document'

like image 733
Adarsh Trivedi Avatar asked Sep 05 '18 11:09

Adarsh Trivedi


1 Answers

You should use EmbeddedDocumentField instead of EmbeddedDocument in DataImportNode:

info = fields.EmbeddedDocumentField(DataImportNodeInfo, required=True)
connection = fields.EmbeddedDocumentField(DataImportConnectionInfo, required=True)

Since the EmbeddedDocumentField is used to reference the EmbeddedDocument.

like image 121
Vitalii Dmitriev Avatar answered Oct 15 '22 20:10

Vitalii Dmitriev