# Buggy code
def includeme(config):
    config.add_api_capability(
        "accounts",
        description="Manage user accounts.",
        url="https://kinto.readthedocs.io/en/latest/api/1.x/accounts.html",
    )

    config.scan("kinto.plugins.accounts.views")

    PERMISSIONS_INHERITANCE_TREE[""].update({"account:create": {}})
    PERMISSIONS_INHERITANCE_TREE["account"] = {
        "write": {"account": ["write"]},
        "read": {"account": ["write", "read"]},
    }


# Traceback (KeyError)
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'

# Fixed code
def includeme(config):
    config.add_api_capability(
        "accounts",
        description="Manage user accounts.",
        url="https://kinto.readthedocs.io/en/latest/api/1.x/accounts.html",
    )

    config.scan("kinto.plugins.accounts.views")

    PERMISSIONS_INHERITANCE_TREE[""].update({"account:create": {}})
    PERMISSIONS_INHERITANCE_TREE["account"] = {
        "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)