From ed1e886f954aba02cd10dfab231bdbe1cca36eca Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Thu, 3 Oct 2024 13:22:35 +0200 Subject: [PATCH] Fix username used in invocation report Fixes https://github.com/galaxyproject/galaxy/issues/18899 --- lib/galaxy/workflow/reports/generators/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/workflow/reports/generators/__init__.py b/lib/galaxy/workflow/reports/generators/__init__.py index 081155ca811b..70cf73787ff2 100644 --- a/lib/galaxy/workflow/reports/generators/__init__.py +++ b/lib/galaxy/workflow/reports/generators/__init__.py @@ -12,6 +12,7 @@ ready_galaxy_markdown_for_export, resolve_invocation_markdown, ) +from galaxy.model import WorkflowInvocation from galaxy.schema import PdfDocumentType @@ -35,7 +36,7 @@ def generate_report_pdf(self, trans, invocation, runtime_report_config_json=None class WorkflowMarkdownGeneratorPlugin(WorkflowReportGeneratorPlugin, metaclass=ABCMeta): """WorkflowReportGeneratorPlugin that generates markdown as base report.""" - def generate_report_json(self, trans, invocation, runtime_report_config_json=None): + def generate_report_json(self, trans, invocation: WorkflowInvocation, runtime_report_config_json=None): """ """ workflow_manager = workflows.WorkflowsManager(trans.app) workflow_encoded_id = trans.app.security.encode_id(invocation.workflow_id) @@ -44,13 +45,15 @@ def generate_report_json(self, trans, invocation, runtime_report_config_json=Non trans, invocation, runtime_report_config_json=runtime_report_config_json ) export_markdown, extra_rendering_data = ready_galaxy_markdown_for_export(trans, internal_markdown) + # Invocations can only be run on history, and user must exist, so this should always work + username = invocation.history and invocation.history.user and invocation.history.user.username rval = { "render_format": "markdown", # Presumably the frontend could render things other ways. "markdown": export_markdown, "invocation_markdown": export_markdown, "model_class": "Report", "id": trans.app.security.encode_id(invocation.workflow_id), - "username": trans.user.username, + "username": username, "title": workflow.name, } rval.update(extra_rendering_data)