We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
'set' object has no attribute extends
```kinto\/views\/permissions.py\", line 107, in get_records\n    perms_by_object_uri.setdefault(subobj_uri, []).extend(resource_perms)\nAttributeError: 'set' object has no attribute 'extend'"```



--- 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/views/permissions.py`
Content:
```
1 import colander
2 from pyramid.security import NO_PERMISSION_REQUIRED, Authenticated
3 from pyramid.settings import aslist
4 
5 from kinto.authorization import PERMISSIONS_INHERITANCE_TREE
6 from kinto.core import utils as core_utils, resource
7 from kinto.core.storage.memory import extract_record_set
8 
9 
10 def allowed_from_settings(settings, principals):
11     """Returns every permissions allowed from settings for the current user.
12     :param settings dict: app settings
13     :param principals list: list of principals of current user
14     :rtype: dict
15 
16     Result example::
17 
18         {
19             "bucket": {"write", "collection:create"},
20             "collection": {"read"}
21         }
22 
23     XXX: This helper will be useful for Kinto/kinto#894
24     """
25     perms_settings = {k: aslist(v) for k, v in settings.items()
26                       if k.endswith('_principals')}
27     from_settings = {}
28     for key, allowed_principals in perms_settings.items():
29         resource_name, permission, _ = key.split('_')
30         # Keep the known permissions only.
31         if resource_name not in PERMISSIONS_INHERITANCE_TREE.keys():
32             continue
33         # Keep the permissions of the current user only.
34         if not bool(set(principals) & set(allowed_principals)):
35             continue
36         # ``collection_create_principals`` means ``collection:create`` in bucket.
37         if permission == 'create':
38             permission = '%s:%s' % (resource_name, permission)
39             resource_name = {  # resource parents.
40                 'bucket': '',
41                 'collection': 'bucket',
42                 'group': 'bucket',
43                 'record': 'collection'}[resource_name]
44         # Store them in a convenient way.
45         from_settings.setdefault(resource_name, set()).add(permission)
46     return from_settings
47 
48 
49 class PermissionsModel(object):
50     id_field = 'id'
51     modified_field = 'last_modified'
52     deleted_field = 'deleted'
53 
54     def __init__(self, request):
55         self.request = request
56 
57     def get_records(self, filters=None, sorting=None, pagination_rules=None,
58                     limit=None, include_deleted=False, parent_id=None):
59         # Invert the permissions inheritance tree.
60         perms_descending_tree = {}
61         for on_resource, tree in PERMISSIONS_INHERITANCE_TREE.items():
62             for obtained_perm, obtained_from in tree.items():
63                 for from_resource, perms in obtained_from.items():
64                     for perm in perms:
65                         perms_descending_tree.setdefault(from_resource, {})\
66                                              .setdefault(perm, {})\
67                                              .setdefault(on_resource, set())\
68                                              .add(obtained_perm)
69 
70         # Obtain current principals.
71         principals = self.request.effective_principals
72         if Authenticated in principals:
73             # Since this view does not require any permission (can be used to
74             # obtain public users permissions), we have to add the prefixed
75             # userid among the principals
76             # (see :mod:`kinto.core.authentication`)
77             userid = self.request.prefixed_userid
78             principals.append(userid)
79 
80         # Query every possible permission of the current user from backend.
81         backend = self.request.registry.permission
82         perms_by_object_uri = backend.get_accessible_objects(principals)
83 
84         # Check settings for every allowed resources.
85         from_settings = allowed_from_settings(self.request.registry.settings, principals)
86 
87         # Expand permissions obtained from backend with the object URIs that
88         # correspond to permissions allowed from settings.
89         allowed_resources = {'bucket', 'collection', 'group'} & set(from_settings.keys())
90         if allowed_resources:
91             storage = self.request.registry.storage
92             every_bucket, _ = storage.get_all(parent_id='', collection_id='bucket')
93             for bucket in every_bucket:
94                 bucket_uri = '/buckets/{id}'.format(**bucket)
95                 for res in allowed_resources:
96                     resource_perms = from_settings[res]
97                     # Bucket is always fetched.
98                     if res == 'bucket':
99                         perms_by_object_uri.setdefault(bucket_uri, []).extend(resource_perms)
100                         continue
101                     # Fetch bucket collections and groups.
102                     # XXX: wrong approach: query in a loop!
103                     every_subobjects, _ = storage.get_all(parent_id=bucket_uri,
104                                                           collection_id=res)
105                     for subobject in every_subobjects:
106                         subobj_uri = bucket_uri + '/{0}s/{1}'.format(res, subobject['id'])
107                         perms_by_object_uri.setdefault(subobj_uri, []).extend(resource_perms)
108 
109         entries = []
110         for object_uri, perms in perms_by_object_uri.items():
111             try:
112                 # Obtain associated res from object URI
113                 resource_name, matchdict = core_utils.view_lookup(self.request,
114                                                                   object_uri)
115             except ValueError:
116                 # Skip permissions entries that are not linked to an object URI
117                 continue
118 
119             # For consistency with event payloads, prefix id with resource name
120             matchdict[resource_name + '_id'] = matchdict.get('id')
121 
122             # Expand implicit permissions using descending tree.
123             permissions = set(perms)
124             for perm in perms:
125                 obtained = perms_descending_tree[resource_name][perm]
126                 # Related to same resource only and not every sub-objects.
127                 # (e.g "bucket:write" gives "bucket:read" but not "group:read")
128                 permissions |= obtained[resource_name]
129 
130             entry = dict(uri=object_uri,
131                          resource_name=resource_name,
132                          permissions=list(permissions),
133                          **matchdict)
134             entries.append(entry)
135 
136         return extract_record_set(entries, filters=filters, sorting=sorting,
137                                   pagination_rules=pagination_rules,
138                                   limit=limit)
139 
140 
141 class PermissionsSchema(resource.ResourceSchema):
142     uri = colander.SchemaNode(colander.String())
143     resource_name = colander.SchemaNode(colander.String())
144     permissions = colander.Sequence(colander.SchemaNode(colander.String()))
145     bucket_id = colander.SchemaNode(colander.String())
146     collection_id = colander.SchemaNode(colander.String(),
147                                         missing=colander.drop)
148     group_id = colander.SchemaNode(colander.String(),
149                                    missing=colander.drop)
150     record_id = colander.SchemaNode(colander.String(),
151                                     missing=colander.drop)
152 
153     class Options:
154         preserve_unknown = False
155 
156 
157 @resource.register(name='permissions',
158                    description='List of user permissions',
159                    collection_path='/permissions',
160                    record_path=None,
161                    collection_methods=('GET',),
162                    permission=NO_PERMISSION_REQUIRED)
163 class Permissions(resource.ShareableResource):
164 
165     schema = PermissionsSchema
166 
167     def __init__(self, request, context=None):
168         super(Permissions, self).__init__(request, context)
169         self.model = PermissionsModel(request)
170 
171     def _extract_sorting(self, limit):
172         # Permissions entries are not stored with timestamp, so do not
173         # force it.
174         result = super(Permissions, self)._extract_sorting(limit)
175         without_last_modified = [s for s in result
176                                  if s.field != self.model.modified_field]
177         return without_last_modified
178 
179     def _extract_filters(self, queryparams=None):
180         result = super(Permissions, self)._extract_filters(queryparams)
181         without_last_modified = [s for s in result
182                                  if s.field != self.model.modified_field]
183         return without_last_modified
184
```
--- 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/views/permissions.py b/kinto/views/permissions.py
--- a/kinto/views/permissions.py
+++ b/kinto/views/permissions.py
@@ -96,7 +96,7 @@
                     resource_perms = from_settings[res]
                     # Bucket is always fetched.
                     if res == 'bucket':
-                        perms_by_object_uri.setdefault(bucket_uri, []).extend(resource_perms)
+                        perms_by_object_uri.setdefault(bucket_uri, set()).update(resource_perms)
                         continue
                     # Fetch bucket collections and groups.
                     # XXX: wrong approach: query in a loop!
@@ -104,7 +104,7 @@
                                                           collection_id=res)
                     for subobject in every_subobjects:
                         subobj_uri = bucket_uri + '/{0}s/{1}'.format(res, subobject['id'])
-                        perms_by_object_uri.setdefault(subobj_uri, []).extend(resource_perms)
+                        perms_by_object_uri.setdefault(subobj_uri, set()).update(resource_perms)
 
         entries = []
         for object_uri, perms in perms_by_object_uri.items():

{"golden_diff": "diff --git a/kinto/views/permissions.py b/kinto/views/permissions.py\n--- a/kinto/views/permissions.py\n+++ b/kinto/views/permissions.py\n@@ -96,7 +96,7 @@\n                     resource_perms = from_settings[res]\n                     # Bucket is always fetched.\n                     if res == 'bucket':\n-                        perms_by_object_uri.setdefault(bucket_uri, []).extend(resource_perms)\n+                        perms_by_object_uri.setdefault(bucket_uri, set()).update(resource_perms)\n                         continue\n                     # Fetch bucket collections and groups.\n                     # XXX: wrong approach: query in a loop!\n@@ -104,7 +104,7 @@\n                                                           collection_id=res)\n                     for subobject in every_subobjects:\n                         subobj_uri = bucket_uri + '/{0}s/{1}'.format(res, subobject['id'])\n-                        perms_by_object_uri.setdefault(subobj_uri, []).extend(resource_perms)\n+                        perms_by_object_uri.setdefault(subobj_uri, set()).update(resource_perms)\n \n         entries = []\n         for object_uri, perms in perms_by_object_uri.items():\n", "issue": "'set' object has no attribute extends\n```kinto\\/views\\/permissions.py\\\", line 107, in get_records\\n    perms_by_object_uri.setdefault(subobj_uri, []).extend(resource_perms)\\nAttributeError: 'set' object has no attribute 'extend'\"```\r\n\r\n\n", "before_files": [{"content": "import colander\nfrom pyramid.security import NO_PERMISSION_REQUIRED, Authenticated\nfrom pyramid.settings import aslist\n\nfrom kinto.authorization import PERMISSIONS_INHERITANCE_TREE\nfrom kinto.core import utils as core_utils, resource\nfrom kinto.core.storage.memory import extract_record_set\n\n\ndef allowed_from_settings(settings, principals):\n    \"\"\"Returns every permissions allowed from settings for the current user.\n    :param settings dict: app settings\n    :param principals list: list of principals of current user\n    :rtype: dict\n\n    Result example::\n\n        {\n            \"bucket\": {\"write\", \"collection:create\"},\n            \"collection\": {\"read\"}\n        }\n\n    XXX: This helper will be useful for Kinto/kinto#894\n    \"\"\"\n    perms_settings = {k: aslist(v) for k, v in settings.items()\n                      if k.endswith('_principals')}\n    from_settings = {}\n    for key, allowed_principals in perms_settings.items():\n        resource_name, permission, _ = key.split('_')\n        # Keep the known permissions only.\n        if resource_name not in PERMISSIONS_INHERITANCE_TREE.keys():\n            continue\n        # Keep the permissions of the current user only.\n        if not bool(set(principals) & set(allowed_principals)):\n            continue\n        # ``collection_create_principals`` means ``collection:create`` in bucket.\n        if permission == 'create':\n            permission = '%s:%s' % (resource_name, permission)\n            resource_name = {  # resource parents.\n                'bucket': '',\n                'collection': 'bucket',\n                'group': 'bucket',\n                'record': 'collection'}[resource_name]\n        # Store them in a convenient way.\n        from_settings.setdefault(resource_name, set()).add(permission)\n    return from_settings\n\n\nclass PermissionsModel(object):\n    id_field = 'id'\n    modified_field = 'last_modified'\n    deleted_field = 'deleted'\n\n    def __init__(self, request):\n        self.request = request\n\n    def get_records(self, filters=None, sorting=None, pagination_rules=None,\n                    limit=None, include_deleted=False, parent_id=None):\n        # Invert the permissions inheritance tree.\n        perms_descending_tree = {}\n        for on_resource, tree in PERMISSIONS_INHERITANCE_TREE.items():\n            for obtained_perm, obtained_from in tree.items():\n                for from_resource, perms in obtained_from.items():\n                    for perm in perms:\n                        perms_descending_tree.setdefault(from_resource, {})\\\n                                             .setdefault(perm, {})\\\n                                             .setdefault(on_resource, set())\\\n                                             .add(obtained_perm)\n\n        # Obtain current principals.\n        principals = self.request.effective_principals\n        if Authenticated in principals:\n            # Since this view does not require any permission (can be used to\n            # obtain public users permissions), we have to add the prefixed\n            # userid among the principals\n            # (see :mod:`kinto.core.authentication`)\n            userid = self.request.prefixed_userid\n            principals.append(userid)\n\n        # Query every possible permission of the current user from backend.\n        backend = self.request.registry.permission\n        perms_by_object_uri = backend.get_accessible_objects(principals)\n\n        # Check settings for every allowed resources.\n        from_settings = allowed_from_settings(self.request.registry.settings, principals)\n\n        # Expand permissions obtained from backend with the object URIs that\n        # correspond to permissions allowed from settings.\n        allowed_resources = {'bucket', 'collection', 'group'} & set(from_settings.keys())\n        if allowed_resources:\n            storage = self.request.registry.storage\n            every_bucket, _ = storage.get_all(parent_id='', collection_id='bucket')\n            for bucket in every_bucket:\n                bucket_uri = '/buckets/{id}'.format(**bucket)\n                for res in allowed_resources:\n                    resource_perms = from_settings[res]\n                    # Bucket is always fetched.\n                    if res == 'bucket':\n                        perms_by_object_uri.setdefault(bucket_uri, []).extend(resource_perms)\n                        continue\n                    # Fetch bucket collections and groups.\n                    # XXX: wrong approach: query in a loop!\n                    every_subobjects, _ = storage.get_all(parent_id=bucket_uri,\n                                                          collection_id=res)\n                    for subobject in every_subobjects:\n                        subobj_uri = bucket_uri + '/{0}s/{1}'.format(res, subobject['id'])\n                        perms_by_object_uri.setdefault(subobj_uri, []).extend(resource_perms)\n\n        entries = []\n        for object_uri, perms in perms_by_object_uri.items():\n            try:\n                # Obtain associated res from object URI\n                resource_name, matchdict = core_utils.view_lookup(self.request,\n                                                                  object_uri)\n            except ValueError:\n                # Skip permissions entries that are not linked to an object URI\n                continue\n\n            # For consistency with event payloads, prefix id with resource name\n            matchdict[resource_name + '_id'] = matchdict.get('id')\n\n            # Expand implicit permissions using descending tree.\n            permissions = set(perms)\n            for perm in perms:\n                obtained = perms_descending_tree[resource_name][perm]\n                # Related to same resource only and not every sub-objects.\n                # (e.g \"bucket:write\" gives \"bucket:read\" but not \"group:read\")\n                permissions |= obtained[resource_name]\n\n            entry = dict(uri=object_uri,\n                         resource_name=resource_name,\n                         permissions=list(permissions),\n                         **matchdict)\n            entries.append(entry)\n\n        return extract_record_set(entries, filters=filters, sorting=sorting,\n                                  pagination_rules=pagination_rules,\n                                  limit=limit)\n\n\nclass PermissionsSchema(resource.ResourceSchema):\n    uri = colander.SchemaNode(colander.String())\n    resource_name = colander.SchemaNode(colander.String())\n    permissions = colander.Sequence(colander.SchemaNode(colander.String()))\n    bucket_id = colander.SchemaNode(colander.String())\n    collection_id = colander.SchemaNode(colander.String(),\n                                        missing=colander.drop)\n    group_id = colander.SchemaNode(colander.String(),\n                                   missing=colander.drop)\n    record_id = colander.SchemaNode(colander.String(),\n                                    missing=colander.drop)\n\n    class Options:\n        preserve_unknown = False\n\n\n@resource.register(name='permissions',\n                   description='List of user permissions',\n                   collection_path='/permissions',\n                   record_path=None,\n                   collection_methods=('GET',),\n                   permission=NO_PERMISSION_REQUIRED)\nclass Permissions(resource.ShareableResource):\n\n    schema = PermissionsSchema\n\n    def __init__(self, request, context=None):\n        super(Permissions, self).__init__(request, context)\n        self.model = PermissionsModel(request)\n\n    def _extract_sorting(self, limit):\n        # Permissions entries are not stored with timestamp, so do not\n        # force it.\n        result = super(Permissions, self)._extract_sorting(limit)\n        without_last_modified = [s for s in result\n                                 if s.field != self.model.modified_field]\n        return without_last_modified\n\n    def _extract_filters(self, queryparams=None):\n        result = super(Permissions, self)._extract_filters(queryparams)\n        without_last_modified = [s for s in result\n                                 if s.field != self.model.modified_field]\n        return without_last_modified\n", "path": "kinto/views/permissions.py"}], "after_files": [{"content": "import colander\nfrom pyramid.security import NO_PERMISSION_REQUIRED, Authenticated\nfrom pyramid.settings import aslist\n\nfrom kinto.authorization import PERMISSIONS_INHERITANCE_TREE\nfrom kinto.core import utils as core_utils, resource\nfrom kinto.core.storage.memory import extract_record_set\n\n\ndef allowed_from_settings(settings, principals):\n    \"\"\"Returns every permissions allowed from settings for the current user.\n    :param settings dict: app settings\n    :param principals list: list of principals of current user\n    :rtype: dict\n\n    Result example::\n\n        {\n            \"bucket\": {\"write\", \"collection:create\"},\n            \"collection\": {\"read\"}\n        }\n\n    XXX: This helper will be useful for Kinto/kinto#894\n    \"\"\"\n    perms_settings = {k: aslist(v) for k, v in settings.items()\n                      if k.endswith('_principals')}\n    from_settings = {}\n    for key, allowed_principals in perms_settings.items():\n        resource_name, permission, _ = key.split('_')\n        # Keep the known permissions only.\n        if resource_name not in PERMISSIONS_INHERITANCE_TREE.keys():\n            continue\n        # Keep the permissions of the current user only.\n        if not bool(set(principals) & set(allowed_principals)):\n            continue\n        # ``collection_create_principals`` means ``collection:create`` in bucket.\n        if permission == 'create':\n            permission = '%s:%s' % (resource_name, permission)\n            resource_name = {  # resource parents.\n                'bucket': '',\n                'collection': 'bucket',\n                'group': 'bucket',\n                'record': 'collection'}[resource_name]\n        # Store them in a convenient way.\n        from_settings.setdefault(resource_name, set()).add(permission)\n    return from_settings\n\n\nclass PermissionsModel(object):\n    id_field = 'id'\n    modified_field = 'last_modified'\n    deleted_field = 'deleted'\n\n    def __init__(self, request):\n        self.request = request\n\n    def get_records(self, filters=None, sorting=None, pagination_rules=None,\n                    limit=None, include_deleted=False, parent_id=None):\n        # Invert the permissions inheritance tree.\n        perms_descending_tree = {}\n        for on_resource, tree in PERMISSIONS_INHERITANCE_TREE.items():\n            for obtained_perm, obtained_from in tree.items():\n                for from_resource, perms in obtained_from.items():\n                    for perm in perms:\n                        perms_descending_tree.setdefault(from_resource, {})\\\n                                             .setdefault(perm, {})\\\n                                             .setdefault(on_resource, set())\\\n                                             .add(obtained_perm)\n\n        # Obtain current principals.\n        principals = self.request.effective_principals\n        if Authenticated in principals:\n            # Since this view does not require any permission (can be used to\n            # obtain public users permissions), we have to add the prefixed\n            # userid among the principals\n            # (see :mod:`kinto.core.authentication`)\n            userid = self.request.prefixed_userid\n            principals.append(userid)\n\n        # Query every possible permission of the current user from backend.\n        backend = self.request.registry.permission\n        perms_by_object_uri = backend.get_accessible_objects(principals)\n\n        # Check settings for every allowed resources.\n        from_settings = allowed_from_settings(self.request.registry.settings, principals)\n\n        # Expand permissions obtained from backend with the object URIs that\n        # correspond to permissions allowed from settings.\n        allowed_resources = {'bucket', 'collection', 'group'} & set(from_settings.keys())\n        if allowed_resources:\n            storage = self.request.registry.storage\n            every_bucket, _ = storage.get_all(parent_id='', collection_id='bucket')\n            for bucket in every_bucket:\n                bucket_uri = '/buckets/{id}'.format(**bucket)\n                for res in allowed_resources:\n                    resource_perms = from_settings[res]\n                    # Bucket is always fetched.\n                    if res == 'bucket':\n                        perms_by_object_uri.setdefault(bucket_uri, set()).update(resource_perms)\n                        continue\n                    # Fetch bucket collections and groups.\n                    # XXX: wrong approach: query in a loop!\n                    every_subobjects, _ = storage.get_all(parent_id=bucket_uri,\n                                                          collection_id=res)\n                    for subobject in every_subobjects:\n                        subobj_uri = bucket_uri + '/{0}s/{1}'.format(res, subobject['id'])\n                        perms_by_object_uri.setdefault(subobj_uri, set()).update(resource_perms)\n\n        entries = []\n        for object_uri, perms in perms_by_object_uri.items():\n            try:\n                # Obtain associated res from object URI\n                resource_name, matchdict = core_utils.view_lookup(self.request,\n                                                                  object_uri)\n            except ValueError:\n                # Skip permissions entries that are not linked to an object URI\n                continue\n\n            # For consistency with event payloads, prefix id with resource name\n            matchdict[resource_name + '_id'] = matchdict.get('id')\n\n            # Expand implicit permissions using descending tree.\n            permissions = set(perms)\n            for perm in perms:\n                obtained = perms_descending_tree[resource_name][perm]\n                # Related to same resource only and not every sub-objects.\n                # (e.g \"bucket:write\" gives \"bucket:read\" but not \"group:read\")\n                permissions |= obtained[resource_name]\n\n            entry = dict(uri=object_uri,\n                         resource_name=resource_name,\n                         permissions=list(permissions),\n                         **matchdict)\n            entries.append(entry)\n\n        return extract_record_set(entries, filters=filters, sorting=sorting,\n                                  pagination_rules=pagination_rules,\n                                  limit=limit)\n\n\nclass PermissionsSchema(resource.ResourceSchema):\n    uri = colander.SchemaNode(colander.String())\n    resource_name = colander.SchemaNode(colander.String())\n    permissions = colander.Sequence(colander.SchemaNode(colander.String()))\n    bucket_id = colander.SchemaNode(colander.String())\n    collection_id = colander.SchemaNode(colander.String(),\n                                        missing=colander.drop)\n    group_id = colander.SchemaNode(colander.String(),\n                                   missing=colander.drop)\n    record_id = colander.SchemaNode(colander.String(),\n                                    missing=colander.drop)\n\n    class Options:\n        preserve_unknown = False\n\n\n@resource.register(name='permissions',\n                   description='List of user permissions',\n                   collection_path='/permissions',\n                   record_path=None,\n                   collection_methods=('GET',),\n                   permission=NO_PERMISSION_REQUIRED)\nclass Permissions(resource.ShareableResource):\n\n    schema = PermissionsSchema\n\n    def __init__(self, request, context=None):\n        super(Permissions, self).__init__(request, context)\n        self.model = PermissionsModel(request)\n\n    def _extract_sorting(self, limit):\n        # Permissions entries are not stored with timestamp, so do not\n        # force it.\n        result = super(Permissions, self)._extract_sorting(limit)\n        without_last_modified = [s for s in result\n                                 if s.field != self.model.modified_field]\n        return without_last_modified\n\n    def _extract_filters(self, queryparams=None):\n        result = super(Permissions, self)._extract_filters(queryparams)\n        without_last_modified = [s for s in result\n                                 if s.field != self.model.modified_field]\n        return without_last_modified\n", "path": "kinto/views/permissions.py"}]}