# Buggy code
def _get_record_or_404(self, record_id):
    """Retrieve record from storage and raise ``404 Not found`` if missing.

    :raises: :exc:`~pyramid:pyramid.httpexceptions.HTTPNotFound` if
        the record is not found.
    """
    try:
        return self.collection.get_record(record_id)
    except storage_exceptions.RecordNotFoundError:
        response = http_error(HTTPNotFound(), errno=ERRORS.INVALID_RESOURCE_ID)
        raise response


# Traceback (TypeError)
2016-02-22 15:21:36,730 ERROR [venusian][waitress] "POST  /v1/buckets/default/collections/test-collection-2aa00fc8-b6e2-41d2-a6a5-28d23ca6fce5/records" ? (? ms) 'str' object does not support item assignment lang=None; exception=Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pyramid/tweens.py", line 20, in excview_tween
response = handler(request)
File "/usr/local/lib/python2.7/dist-packages/pyramid_tm/__init__.py", line 101, in tm_tween
reraise(*exc_info)
File "/usr/local/lib/python2.7/dist-packages/pyramid_tm/__init__.py", line 83, in tm_tween
response = handler(request)
File "/usr/local/lib/python2.7/dist-packages/pyramid/router.py", line 145, in handle_request
view_name
File "/usr/local/lib/python2.7/dist-packages/pyramid/view.py", line 541, in _call_view
response = view_callable(context, request)
File "/usr/local/lib/python2.7/dist-packages/pyramid/config/views.py", line 385, in viewresult_to_response
result = view(context, request)
File "/usr/local/lib/python2.7/dist-packages/pyramid/config/views.py", line 507, in _requestonly_view
response = view(request)
File "/usr/local/lib/python2.7/dist-packages/kinto/plugins/default_bucket/__init__.py", line 108, in default_bucket
create_bucket(request, bucket_id)
File "/usr/local/lib/python2.7/dist-packages/kinto/plugins/default_bucket/__init__.py", line 35, in create_bucket
bucket = resource.model.create_record({'id': bucket_id})
File "/usr/local/lib/python2.7/dist-packages/cliquet/resource/model.py", line 294, in create_record
unique_fields)
File "/usr/local/lib/python2.7/dist-packages/cliquet/resource/model.py", line 177, in create_record
auth=self.auth)
File "/usr/local/lib/python2.7/dist-packages/cliquet/storage/postgresql/__init__.py", line 234, in create
for_creation=True)
File "/usr/local/lib/python2.7/dist-packages/cliquet/storage/postgresql/__init__.py", line 734, in _check_unicity
record = self.get(collection_id, parent_id, existing['id'])
File "/usr/local/lib/python2.7/dist-packages/cliquet/storage/postgresql/__init__.py", line 263, in get
record[id_field] = object_id
TypeError: 'str' object does not support item assignment; uid=d3f58ae9f309fa494504a2347a13f80c811b64e9d8815299b9c1467f85854288; errno=None; agent=node-superagent/1.7.2; authn_type=BasicAuth; collection_id=bucket; collection_timestamp=1456154496656

# Fixed code
def _get_record_or_404(self, record_id):
    """Retrieve record from storage and raise ``404 Not found`` if missing.

    :raises: :exc:`~pyramid:pyramid.httpexceptions.HTTPNotFound` if
        the record is not found.
    """
    if self.context and self.context.current_record:
        # Set during authorization. Save a storage hit.
        return self.context.current_record

    try:
        return self.collection.get_record(record_id)
    except storage_exceptions.RecordNotFoundError:
        response = http_error(HTTPNotFound(), errno=ERRORS.INVALID_RESOURCE_ID)
        raise response