{"action":"created","issue":{"url":"https://api.github.com/repos/pyeve/eve/issues/1170","repository_url":"https://api.github.com/repos/pyeve/eve","labels_url":"https://api.github.com/repos/pyeve/eve/issues/1170/labels{/name}","comments_url":"https://api.github.com/repos/pyeve/eve/issues/1170/comments","events_url":"https://api.github.com/repos/pyeve/eve/issues/1170/events","html_url":"https://github.com/pyeve/eve/issues/1170","id":338374975,"node_id":"MDU6SXNzdWUzMzgzNzQ5NzU=","number":1170,"title":"Internal error with embedded None field","user":{"login":"gwainer","id":2478582,"node_id":"MDQ6VXNlcjI0Nzg1ODI=","avatar_url":"https://avatars2.githubusercontent.com/u/2478582?v=4","gravatar_id":"","url":"https://api.github.com/users/gwainer","html_url":"https://github.com/gwainer","followers_url":"https://api.github.com/users/gwainer/followers","following_url":"https://api.github.com/users/gwainer/following{/other_user}","gists_url":"https://api.github.com/users/gwainer/gists{/gist_id}","starred_url":"https://api.github.com/users/gwainer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwainer/subscriptions","organizations_url":"https://api.github.com/users/gwainer/orgs","repos_url":"https://api.github.com/users/gwainer/repos","events_url":"https://api.github.com/users/gwainer/events{/privacy}","received_events_url":"https://api.github.com/users/gwainer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-04T21:03:14Z","updated_at":"2018-08-14T01:19:10Z","closed_at":null,"author_association":"NONE","body":"I believe I've stumbled in an issue when getting second-level embedded documents if the first level is None.\r\n\r\n### Expected Behavior\r\nConsidering the schemas below:\r\n\r\n```python\r\ndevice_schema = {\r\n    'site': {\r\n        'type': 'objectid',\r\n        'data_relation': {\r\n            'resource': 'sites',\r\n            'field': '_id',\r\n            'embeddable': True\r\n        },\r\n        'nullable': True,\r\n    },\r\n},\r\nsite_schema = {\r\n    'employees': {\r\n        'type': 'list',\r\n        'schema': {\r\n            'type': 'objectid',\r\n            'required': True,\r\n            'data_relation': {\r\n                'resource': 'employees',\r\n                'field': '_id',\r\n                'embeddable': True\r\n            },\r\n        }\r\n    },\r\n}\r\n```\r\n\r\n`device` has an embedded `site` inside, `site` has a list of `employees`. When `device.site` is None, since it is `nullable`, if you set embedded documents as `embedded={\"site\": 1, \"site.employees\": 1}`, an internal error occurs.\r\n\r\n\r\n### Actual Behavior\r\n\r\nWe have an internal error, and it cannot be avoid by pre_get event hooks, since request cannot be altered inside hooks. Traceback:\r\n\r\n```python\r\nTraceback (most recent call last):\r\n  File \"/eve/lib/python3.5/site-packages/gevent/pywsgi.py\", line 935, in handle_one_response\r\n    self.run_application()\r\n  File \"/eve/lib/python3.5/site-packages/gevent/pywsgi.py\", line 908, in run_application\r\n    self.result = self.application(self.environ, self.start_response)\r\n  File \"/eve/lib/python3.5/site-packages/eve/flaskapp.py\", line 1043, in __call__\r\n    return super(Eve, self).__call__(environ, start_response)\r\n  File \"/eve/lib/python3.5/site-packages/flask/app.py\", line 2309, in __call__\r\n    return self.wsgi_app(environ, start_response)\r\n  File \"/eve/lib/python3.5/site-packages/flask/app.py\", line 2295, in wsgi_app\r\n    response = self.handle_exception(e)\r\n  File \"/eve/lib/python3.5/site-packages/flask_cors/extension.py\", line 161, in wrapped_function\r\n    return cors_after_request(app.make_response(f(*args, **kwargs)))\r\n  File \"/eve/lib/python3.5/site-packages/flask/app.py\", line 1741, in handle_exception\r\n    reraise(exc_type, exc_value, tb)\r\n  File \"/eve/lib/python3.5/site-packages/flask/_compat.py\", line 35, in reraise\r\n    raise value\r\n  File \"/eve/lib/python3.5/site-packages/flask/app.py\", line 2292, in wsgi_app\r\n    response = self.full_dispatch_request()\r\n  File \"/eve/lib/python3.5/site-packages/flask/app.py\", line 1815, in full_dispatch_request\r\n    rv = self.handle_user_exception(e)\r\n  File \"/eve/lib/python3.5/site-packages/flask_cors/extension.py\", line 161, in wrapped_function\r\n    return cors_after_request(app.make_response(f(*args, **kwargs)))\r\n  File \"/eve/lib/python3.5/site-packages/flask/app.py\", line 1718, in handle_user_exception\r\n    reraise(exc_type, exc_value, tb)\r\n  File \"/eve/lib/python3.5/site-packages/flask/_compat.py\", line 35, in reraise\r\n    raise value\r\n  File \"/eve/lib/python3.5/site-packages/flask/app.py\", line 1813, in full_dispatch_request\r\n    rv = self.dispatch_request()\r\n  File \"/eve/lib/python3.5/site-packages/flask/app.py\", line 1799, in dispatch_request\r\n    return self.view_functions[rule.endpoint](**req.view_args)\r\n  File \"/eve/lib/python3.5/site-packages/eve/endpoints.py\", line 94, in item_endpoint\r\n    response = getitem(resource, **lookup)\r\n  File \"/eve/lib/python3.5/site-packages/eve/methods/common.py\", line 297, in rate_limited\r\n    return f(*args, **kwargs)\r\n  File \"/eve/lib/python3.5/site-packages/eve/auth.py\", line 78, in decorated\r\n    return f(*args, **kwargs)\r\n  File \"/eve/lib/python3.5/site-packages/eve/methods/common.py\", line 1181, in decorated\r\n    r = f(resource, **combined_args)\r\n  File \"/eve/lib/python3.5/site-packages/eve/methods/get.py\", line 261, in getitem\r\n    return getitem_internal(resource, **lookup)\r\n  File \"/eve/lib/python3.5/site-packages/eve/methods/get.py\", line 351, in getitem_internal\r\n    build_response_document(document, resource, embedded_fields, latest_doc)\r\n  File \"/eve/lib/python3.5/site-packages/eve/methods/common.py\", line 612, in build_response_document\r\n    resolve_embedded_documents(document, resource, embedded_fields)\r\n  File \"/eve/lib/python3.5/site-packages/eve/methods/common.py\", line 934, in resolve_embedded_documents\r\n    if last_field not in subdocument:\r\nTypeError: argument of type 'NoneType' is not iterable\r\n```\r\n\r\n### Environment\r\n\r\n* Python version: 3.5\r\n* Eve version: 0.8\r\n"},"comment":{"url":"https://api.github.com/repos/pyeve/eve/issues/comments/412720585","html_url":"https://github.com/pyeve/eve/issues/1170#issuecomment-412720585","issue_url":"https://api.github.com/repos/pyeve/eve/issues/1170","id":412720585,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMjcyMDU4NQ==","user":{"login":"gwainer","id":2478582,"node_id":"MDQ6VXNlcjI0Nzg1ODI=","avatar_url":"https://avatars2.githubusercontent.com/u/2478582?v=4","gravatar_id":"","url":"https://api.github.com/users/gwainer","html_url":"https://github.com/gwainer","followers_url":"https://api.github.com/users/gwainer/followers","following_url":"https://api.github.com/users/gwainer/following{/other_user}","gists_url":"https://api.github.com/users/gwainer/gists{/gist_id}","starred_url":"https://api.github.com/users/gwainer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwainer/subscriptions","organizations_url":"https://api.github.com/users/gwainer/orgs","repos_url":"https://api.github.com/users/gwainer/repos","events_url":"https://api.github.com/users/gwainer/events{/privacy}","received_events_url":"https://api.github.com/users/gwainer/received_events","type":"User","site_admin":false},"created_at":"2018-08-14T01:19:10Z","updated_at":"2018-08-14T01:19:10Z","author_association":"NONE","body":"It works OK now. Thank you for the fix.\n\nOn Wed, Aug 8, 2018 at 5:56 AM Nicola Iarocci <notifications@github.com>\nwrote:\n\n> Hi, on Eve 0.8.1-dev the following test passes:\n>\n>     def test_triage_issue_1170(self):\n>         self.app.register_resource(\n>             \"devices\", {\n>                 \"schema\": {\n>                     'site': {\n>                         'type': 'objectid',\n>                         'data_relation': {\n>                             'resource': 'sites',\n>                             'field': '_id',\n>                             'embeddable': True\n>                         },\n>                         'nullable': True, }}})\n>         self.app.register_resource(\n>             \"sites\", {\n>                 \"schema\": {\n>                     'employees': {\n>                         'type': 'list',\n>                         'schema': {\n>                             'type': 'objectid',\n>                             'required': True,\n>                             'data_relation': {\n>                                 'resource': 'employees',\n>                                 'field': '_id',\n>                                 'embeddable': True\n>                         }}}}})\n>\n>         data = {\"site\": None}\n>         r, status = self.post(\"devices\", data=data)\n>         self.assert201(status)\n>\n>         raw_r = self.test_client.get('devices?embedded={\"site\":1,\"sites.employees\": 1}')\n>         self.assert200(raw_r.status_code)\n>\n> Is there anything more I need to do in order to reproduce the ticket? Or\n> maybe you can verify if this is still an issue with v0.8.1-dev?\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/pyeve/eve/issues/1170#issuecomment-411336350>, or mute\n> the thread\n> <https://github.com/notifications/unsubscribe-auth/ACXR9nlSdQWBAPHI7H5-cAa5PBePqMwNks5uOqfQgaJpZM4VDBPo>\n> .\n>\n"}}
{"actor":{"display_login":"gwainer"}}