{"action":"opened","issue":{"url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/904","labels_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/904/labels{/name}","comments_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/904/comments","events_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/904/events","html_url":"https://github.com/MongoEngine/mongoengine/issues/904","id":60069710,"number":904,"title":"error while using \"db_field\" parameter in multi-level embedded documents","user":{"login":"ms5","id":5268998,"avatar_url":"https://avatars.githubusercontent.com/u/5268998?v=3","gravatar_id":"","url":"https://api.github.com/users/ms5","html_url":"https://github.com/ms5","followers_url":"https://api.github.com/users/ms5/followers","following_url":"https://api.github.com/users/ms5/following{/other_user}","gists_url":"https://api.github.com/users/ms5/gists{/gist_id}","starred_url":"https://api.github.com/users/ms5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ms5/subscriptions","organizations_url":"https://api.github.com/users/ms5/orgs","repos_url":"https://api.github.com/users/ms5/repos","events_url":"https://api.github.com/users/ms5/events{/privacy}","received_events_url":"https://api.github.com/users/ms5/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-06T07:42:02Z","updated_at":"2015-03-06T07:42:02Z","closed_at":null,"body":"The following code is an example to reconstruct what's going wrong. The main problem seems to be the use of ```db_field``` in the second level of the embedded document (In the example this is ```class B```)\r\n\r\n```python\r\ndata = {'b': {'c': [{'x': 1.0, 'y': 2.0}]}}\r\n\r\nclass C(EmbeddedDocument):\r\n    x = FloatField(db_field='fx')\r\n    y = FloatField(db_field='fy')\r\n\r\nclass B(EmbeddedDocument):\r\n    c = ListField(EmbeddedDocumentField(C), db_field='fc')\r\n\r\nclass A(EmbeddedDocument):\r\n    b = EmbeddedDocumentField(B, db_field='fb')\r\n\r\na = A(**data)\r\na.validate()\r\n```\r\n\r\nIf I run this, it throws an exception:\r\n\r\n```python\r\n  File \"/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mongoengine/base/document.py\", line 424, in validate\r\n    raise ValidationError(message, errors=errors)\r\nmongoengine.errors.ValidationError: ValidationError (A:None) (c.Invalid embedded document instance provided to an EmbeddedDocumentField: ['b'])\r\n```\r\n\r\n\r\nBut it runs through if I remove the ```db_field``` attribute in ```class B```:\r\n\r\n```python\r\nclass B(EmbeddedDocument):\r\n    c = ListField(EmbeddedDocumentField(C))\r\n```\r\n\r\nWhile digging in to this problem I found out that the exception is actually correct when saying the Document has the wrong format. \r\n\r\nwhile running a simple print on the working an non working version, the type differs. \r\n\r\n```python\r\nprint(a.b.c[0])\r\nprint(type(a.b.c[0]))\r\n\r\n# wrong\r\n{'x': 1.0, 'y': 2.0}\r\n<class 'mongoengine.base.datastructures.BaseDict'>\r\n\r\n# good\r\nC object\r\n<class '__main__.C'>\r\n```\r\n\r\n\r\n\r\n\r\n"}}