# Buggy code
def display(
    self,
    trans,
    history_content_id,
    history_id,
    preview=False,
    filename=None,
    to_ext=None,
    raw=False,
    **kwd,
):
    """
    GET /api/histories/{encoded_history_id}/contents/{encoded_content_id}/display
    Displays history content (dataset).

    The query parameter 'raw' should be considered experimental and may be dropped at
    some point in the future without warning. Generally, data should be processed by its
    datatype prior to display (the defult if raw is unspecified or explicitly false.
    """
    decoded_content_id = self.decode_id(history_content_id)
    raw = util.string_as_bool_or_none(raw)

    rval = ""
    try:
        hda = self.hda_manager.get_accessible(decoded_content_id, trans.user)
        if raw:
            if filename and filename != "index":
                object_store = trans.app.object_store
                dir_name = hda.dataset.extra_files_path_name
                file_path = object_store.get_filename(
                    hda.dataset, extra_dir=dir_name, alt_name=filename
                )
            else:
                file_path = hda.file_name
            rval = open(file_path, "rb")
        else:
            display_kwd = kwd.copy()
            if "key" in display_kwd:
                del display_kwd["key"]
            rval = hda.datatype.display_data(
                trans, hda, preview, filename, to_ext, **display_kwd
            )
    except Exception as e:
        log.exception(
            "Error getting display data for dataset (%s) from history (%s)",
            history_content_id,
            history_id,
        )
        trans.response.status = 500
        rval = "Could not get display data for dataset: %s" % util.unicodify(e)
    return rval


# Traceback (galaxy.exceptions.ItemAccessibilityException)
galaxy.webapps.galaxy.api.datasets ERROR 2021-02-24 13:04:42,977 [p:41176,w:3,m:0] [uWSGIWorker3Core0] Error getting display data for dataset (e6693f4d1a4d9f91) from history (e9859c1e537d1ced)
Traceback (most recent call last):
File "lib/galaxy/webapps/galaxy/api/datasets.py", line 441, in display
hda = self.hda_manager.get_accessible(decoded_content_id, trans.user)
File "lib/galaxy/managers/secured.py", line 33, in get_accessible
return self.error_unless_accessible(item, user, **kwargs)
File "lib/galaxy/managers/secured.py", line 43, in error_unless_accessible
raise exceptions.ItemAccessibilityException("%s is not accessible by user" % (self.model_class.__name__))
galaxy.exceptions.ItemAccessibilityException: HistoryDatasetAssociation is not accessible by user
10.10.58.115 - - [24/Feb/2021:13:04:42 +0200] "GET /api/histories/e9859c1e537d1ced/contents/e6693f4d1a4d9f91/display HTTP/1.1" 500 - "-" "python-requests/2.25.1"

# Fixed code
def display(
    self,
    trans,
    history_content_id,
    history_id,
    preview=False,
    filename=None,
    to_ext=None,
    raw=False,
    **kwd,
):
    """
    GET /api/histories/{encoded_history_id}/contents/{encoded_content_id}/display
    Displays history content (dataset).

    The query parameter 'raw' should be considered experimental and may be dropped at
    some point in the future without warning. Generally, data should be processed by its
    datatype prior to display (the defult if raw is unspecified or explicitly false.
    """
    decoded_content_id = self.decode_id(history_content_id)
    raw = util.string_as_bool_or_none(raw)

    rval = ""
    try:
        hda = self.hda_manager.get_accessible(decoded_content_id, trans.user)
        if raw:
            if filename and filename != "index":
                object_store = trans.app.object_store
                dir_name = hda.dataset.extra_files_path_name
                file_path = object_store.get_filename(
                    hda.dataset, extra_dir=dir_name, alt_name=filename
                )
            else:
                file_path = hda.file_name
            rval = open(file_path, "rb")
        else:
            display_kwd = kwd.copy()
            if "key" in display_kwd:
                del display_kwd["key"]
            rval = hda.datatype.display_data(
                trans, hda, preview, filename, to_ext, **display_kwd
            )
    except galaxy_exceptions.MessageException:
        raise
    except Exception as e:
        log.exception(
            "Server error getting display data for dataset (%s) from history (%s)",
            history_content_id,
            history_id,
        )
        raise galaxy_exceptions.InternalServerError(
            f"Could not get display data for dataset: {util.unicodify(e)}"
        )
    return rval