# Buggy code
def object_truncate(self, account, container, obj, version=None, size=None, **kwargs):
    """
    Truncate object at specified size. Only shrink is supported.
    A download may occur if size is not on chunk boundaries.

    :param account: name of the account in which the object is stored
    :param container: name of the container in which the object is stored
    :param obj: name of the object to query
    :param version: version of the object to query
    :param size: new size of object
    """

    # code copied from object_fetch (should be factorized !)
    meta, raw_chunks = self.object_locate(
        account, container, obj, version=version, **kwargs
    )
    chunk_method = meta["chunk_method"]
    storage_method = STORAGE_METHODS.load(chunk_method)
    chunks = _sort_chunks(raw_chunks, storage_method.ec)

    for pos in sorted(chunks.keys()):
        chunk = chunks[pos][0]
        if size >= chunk["offset"] and size <= chunk["offset"] + chunk["size"]:
            break
    else:
        raise exc.OioException("No chunk found at position %d" % size)

    if chunk["offset"] != size:
        # retrieve partial chunk
        ret = self.object_fetch(
            account,
            container,
            obj,
            version=version,
            ranges=[(chunk["offset"], size - 1)],
        )
        # TODO implement a proper object_update
        pos = int(chunk["pos"].split(".")[0])
        self.object_create(
            account,
            container,
            obj_name=obj,
            data=ret[1],
            meta_pos=pos,
            content_id=meta["id"],
        )

    return self.container.content_truncate(
        account, container, obj, version=version, size=size, **kwargs
    )


# Traceback (KeyError)
Checking object "account=AUTH_demo, container=testing, obj=magic"
Checking container "account=AUTH_demo, container=testing, obj=magic"
Checking account "account=AUTH_demo, container=testing, obj=magic"
Exception object "account=AUTH_demo, container=testing, obj=magic": ('reqid=None', 'Connection aborted.', HTTPException('got more than 100 headers',))
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/eventlet/greenpool.py", line 82, in _spawn_n_impl
func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/oio/crawler/integrity.py", line 244, in check_obj
self.check_obj_policy(target.copy(), meta, results)
File "/usr/lib/python2.7/site-packages/oio/crawler/integrity.py", line 185, in check_obj_policy
stg_met = STORAGE_METHODS.load(obj_meta['chunk_method'])
KeyError: 'chunk_method'

Report
Accounts checked  : 1

Containers checked: 1

Objects checked   : 0
Exceptions        : 1

Chunks checked    : 0

# Fixed code
def object_truncate(self, account, container, obj, version=None, size=None, **kwargs):
    """
    Truncate object at specified size. Only shrink is supported.
    A download may occur if size is not on chunk boundaries.

    :param account: name of the account in which the object is stored
    :param container: name of the container in which the object is stored
    :param obj: name of the object to query
    :param version: version of the object to query
    :param size: new size of object
    """

    # code copied from object_fetch (should be factorized !)
    meta, raw_chunks = self.object_locate(
        account, container, obj, version=version, properties=False, **kwargs
    )
    chunk_method = meta["chunk_method"]
    storage_method = STORAGE_METHODS.load(chunk_method)
    chunks = _sort_chunks(raw_chunks, storage_method.ec)

    for pos in sorted(chunks.keys()):
        chunk = chunks[pos][0]
        if size >= chunk["offset"] and size <= chunk["offset"] + chunk["size"]:
            break
    else:
        raise exc.OioException("No chunk found at position %d" % size)

    if chunk["offset"] != size:
        # retrieve partial chunk
        ret = self.object_fetch(
            account,
            container,
            obj,
            version=version,
            ranges=[(chunk["offset"], size - 1)],
        )
        # TODO implement a proper object_update
        pos = int(chunk["pos"].split(".")[0])
        self.object_create(
            account,
            container,
            obj_name=obj,
            data=ret[1],
            meta_pos=pos,
            content_id=meta["id"],
        )

    return self.container.content_truncate(
        account, container, obj, version=version, size=size, **kwargs
    )