We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Accounts post API crashes with unset id (if basicauth is enabled too)
```
gsurita-30820:~ gsurita$ echo '{"data": {"password": "me"}}' | http post localhost:8888/v1/accounts -a foo:bar
HTTP/1.1 500 Internal Server Error
(...)
```

```
Traceback (most recent call last):
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/__init__.py", line 119, in tm_tween
    reraise(*exc_info)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/compat.py", line 15, in reraise
    raise value
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/__init__.py", line 98, in tm_tween
    response = handler(request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/router.py", line 155, in handle_request
    view_name
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/view.py", line 612, in _call_view
    response = view_callable(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/config/views.py", line 181, in __call__
    return view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 389, in attr_view
    return view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 367, in predicate_wrapper
    return view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 300, in secured_view
    return view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 438, in rendered_view
    result = view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/cornice/service.py", line 491, in wrapper
    response = view_()
  File "/Users/gsurita/kinto/kinto/kinto/plugins/accounts/views.py", line 81, in collection_post
    result = super(Account, self).collection_post()
  File "/Users/gsurita/kinto/kinto/kinto/core/resource/__init__.py", line 341, in collection_post
    new_record = self.process_record(new_record)
  File "/Users/gsurita/kinto/kinto/kinto/plugins/accounts/views.py", line 102, in process_record
    if new[self.model.id_field] != self.request.selected_userid:
KeyError: 'id'
```
Accounts post API crashes with unset id (if basicauth is enabled too)
```
gsurita-30820:~ gsurita$ echo '{"data": {"password": "me"}}' | http post localhost:8888/v1/accounts -a foo:bar
HTTP/1.1 500 Internal Server Error
(...)
```

```
Traceback (most recent call last):
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/__init__.py", line 119, in tm_tween
    reraise(*exc_info)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/compat.py", line 15, in reraise
    raise value
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/__init__.py", line 98, in tm_tween
    response = handler(request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/router.py", line 155, in handle_request
    view_name
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/view.py", line 612, in _call_view
    response = view_callable(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/config/views.py", line 181, in __call__
    return view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 389, in attr_view
    return view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 367, in predicate_wrapper
    return view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 300, in secured_view
    return view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 438, in rendered_view
    result = view(context, request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/cornice/service.py", line 491, in wrapper
    response = view_()
  File "/Users/gsurita/kinto/kinto/kinto/plugins/accounts/views.py", line 81, in collection_post
    result = super(Account, self).collection_post()
  File "/Users/gsurita/kinto/kinto/kinto/core/resource/__init__.py", line 341, in collection_post
    new_record = self.process_record(new_record)
  File "/Users/gsurita/kinto/kinto/kinto/plugins/accounts/views.py", line 102, in process_record
    if new[self.model.id_field] != self.request.selected_userid:
KeyError: 'id'
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kinto/plugins/accounts/__init__.py`
Content:
```
1 from kinto.authorization import PERMISSIONS_INHERITANCE_TREE
2 
3 
4 def includeme(config):
5     config.add_api_capability(
6         'accounts',
7         description='Manage user accounts.',
8         url='https://kinto.readthedocs.io/en/latest/api/1.x/accounts.html')
9 
10     config.scan('kinto.plugins.accounts.views')
11 
12     PERMISSIONS_INHERITANCE_TREE[''].update({
13         'account:create': {}
14     })
15     PERMISSIONS_INHERITANCE_TREE['account'] = {
16         'write': {'account': ['write']},
17         'read': {'account': ['write', 'read']}
18     }
19
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kinto/plugins/accounts/__init__.py b/kinto/plugins/accounts/__init__.py
--- a/kinto/plugins/accounts/__init__.py
+++ b/kinto/plugins/accounts/__init__.py
@@ -1,4 +1,5 @@
 from kinto.authorization import PERMISSIONS_INHERITANCE_TREE
+from pyramid.exceptions import ConfigurationError
 
 
 def includeme(config):
@@ -16,3 +17,12 @@
         'write': {'account': ['write']},
         'read': {'account': ['write', 'read']}
     }
+
+    # Add some safety to avoid weird behaviour with basicauth default policy.
+    settings = config.get_settings()
+    auth_policies = settings['multiauth.policies']
+    if 'basicauth' in auth_policies and 'account' in auth_policies:
+        if auth_policies.index('basicauth') < auth_policies.index('account'):
+            error_msg = ("'basicauth' should not be mentioned before 'account' "
+                         "in 'multiauth.policies' setting.")
+            raise ConfigurationError(error_msg)

{"golden_diff": "diff --git a/kinto/plugins/accounts/__init__.py b/kinto/plugins/accounts/__init__.py\n--- a/kinto/plugins/accounts/__init__.py\n+++ b/kinto/plugins/accounts/__init__.py\n@@ -1,4 +1,5 @@\n from kinto.authorization import PERMISSIONS_INHERITANCE_TREE\n+from pyramid.exceptions import ConfigurationError\n \n \n def includeme(config):\n@@ -16,3 +17,12 @@\n         'write': {'account': ['write']},\n         'read': {'account': ['write', 'read']}\n     }\n+\n+    # Add some safety to avoid weird behaviour with basicauth default policy.\n+    settings = config.get_settings()\n+    auth_policies = settings['multiauth.policies']\n+    if 'basicauth' in auth_policies and 'account' in auth_policies:\n+        if auth_policies.index('basicauth') < auth_policies.index('account'):\n+            error_msg = (\"'basicauth' should not be mentioned before 'account' \"\n+                         \"in 'multiauth.policies' setting.\")\n+            raise ConfigurationError(error_msg)\n", "issue": "Accounts post API crashes with unset id (if basicauth is enabled too)\n```\r\ngsurita-30820:~ gsurita$ echo '{\"data\": {\"password\": \"me\"}}' | http post localhost:8888/v1/accounts -a foo:bar\r\nHTTP/1.1 500 Internal Server Error\r\n(...)\r\n```\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/tweens.py\", line 22, in excview_tween\r\n    response = handler(request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/__init__.py\", line 119, in tm_tween\r\n    reraise(*exc_info)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/compat.py\", line 15, in reraise\r\n    raise value\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/__init__.py\", line 98, in tm_tween\r\n    response = handler(request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/router.py\", line 155, in handle_request\r\n    view_name\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/view.py\", line 612, in _call_view\r\n    response = view_callable(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/config/views.py\", line 181, in __call__\r\n    return view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 389, in attr_view\r\n    return view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 367, in predicate_wrapper\r\n    return view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 300, in secured_view\r\n    return view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 438, in rendered_view\r\n    result = view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 147, in _requestonly_view\r\n    response = view(request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/cornice/service.py\", line 491, in wrapper\r\n    response = view_()\r\n  File \"/Users/gsurita/kinto/kinto/kinto/plugins/accounts/views.py\", line 81, in collection_post\r\n    result = super(Account, self).collection_post()\r\n  File \"/Users/gsurita/kinto/kinto/kinto/core/resource/__init__.py\", line 341, in collection_post\r\n    new_record = self.process_record(new_record)\r\n  File \"/Users/gsurita/kinto/kinto/kinto/plugins/accounts/views.py\", line 102, in process_record\r\n    if new[self.model.id_field] != self.request.selected_userid:\r\nKeyError: 'id'\r\n```\nAccounts post API crashes with unset id (if basicauth is enabled too)\n```\r\ngsurita-30820:~ gsurita$ echo '{\"data\": {\"password\": \"me\"}}' | http post localhost:8888/v1/accounts -a foo:bar\r\nHTTP/1.1 500 Internal Server Error\r\n(...)\r\n```\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/tweens.py\", line 22, in excview_tween\r\n    response = handler(request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/__init__.py\", line 119, in tm_tween\r\n    reraise(*exc_info)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/compat.py\", line 15, in reraise\r\n    raise value\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid_tm/__init__.py\", line 98, in tm_tween\r\n    response = handler(request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/router.py\", line 155, in handle_request\r\n    view_name\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/view.py\", line 612, in _call_view\r\n    response = view_callable(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/config/views.py\", line 181, in __call__\r\n    return view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 389, in attr_view\r\n    return view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 367, in predicate_wrapper\r\n    return view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 300, in secured_view\r\n    return view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 438, in rendered_view\r\n    result = view(context, request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/pyramid/viewderivers.py\", line 147, in _requestonly_view\r\n    response = view(request)\r\n  File \"/Users/gsurita/kinto/kinto/.venv/lib/python3.6/site-packages/cornice/service.py\", line 491, in wrapper\r\n    response = view_()\r\n  File \"/Users/gsurita/kinto/kinto/kinto/plugins/accounts/views.py\", line 81, in collection_post\r\n    result = super(Account, self).collection_post()\r\n  File \"/Users/gsurita/kinto/kinto/kinto/core/resource/__init__.py\", line 341, in collection_post\r\n    new_record = self.process_record(new_record)\r\n  File \"/Users/gsurita/kinto/kinto/kinto/plugins/accounts/views.py\", line 102, in process_record\r\n    if new[self.model.id_field] != self.request.selected_userid:\r\nKeyError: 'id'\r\n```\n", "before_files": [{"content": "from kinto.authorization import PERMISSIONS_INHERITANCE_TREE\n\n\ndef includeme(config):\n    config.add_api_capability(\n        'accounts',\n        description='Manage user accounts.',\n        url='https://kinto.readthedocs.io/en/latest/api/1.x/accounts.html')\n\n    config.scan('kinto.plugins.accounts.views')\n\n    PERMISSIONS_INHERITANCE_TREE[''].update({\n        'account:create': {}\n    })\n    PERMISSIONS_INHERITANCE_TREE['account'] = {\n        'write': {'account': ['write']},\n        'read': {'account': ['write', 'read']}\n    }\n", "path": "kinto/plugins/accounts/__init__.py"}], "after_files": [{"content": "from kinto.authorization import PERMISSIONS_INHERITANCE_TREE\nfrom pyramid.exceptions import ConfigurationError\n\n\ndef includeme(config):\n    config.add_api_capability(\n        'accounts',\n        description='Manage user accounts.',\n        url='https://kinto.readthedocs.io/en/latest/api/1.x/accounts.html')\n\n    config.scan('kinto.plugins.accounts.views')\n\n    PERMISSIONS_INHERITANCE_TREE[''].update({\n        'account:create': {}\n    })\n    PERMISSIONS_INHERITANCE_TREE['account'] = {\n        'write': {'account': ['write']},\n        'read': {'account': ['write', 'read']}\n    }\n\n    # Add some safety to avoid weird behaviour with basicauth default policy.\n    settings = config.get_settings()\n    auth_policies = settings['multiauth.policies']\n    if 'basicauth' in auth_policies and 'account' in auth_policies:\n        if auth_policies.index('basicauth') < auth_policies.index('account'):\n            error_msg = (\"'basicauth' should not be mentioned before 'account' \"\n                         \"in 'multiauth.policies' setting.\")\n            raise ConfigurationError(error_msg)\n", "path": "kinto/plugins/accounts/__init__.py"}]}