From a2c304081a6ca4738ae7bba53236d4637f950172 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 23 Aug 2024 21:56:00 +0200 Subject: [PATCH] Catch and display exceptions when importing malformatted yaml workflows --- lib/galaxy/managers/workflows.py | 10 +++++++--- lib/galaxy_test/api/test_workflows.py | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/managers/workflows.py b/lib/galaxy/managers/workflows.py index 1259dd7719ad..0d970de24293 100644 --- a/lib/galaxy/managers/workflows.py +++ b/lib/galaxy/managers/workflows.py @@ -14,6 +14,7 @@ ) import sqlalchemy +import yaml from gxformat2 import ( from_galaxy_native, ImporterGalaxyInterface, @@ -620,9 +621,12 @@ def normalize_workflow_format(self, trans, as_dict): galaxy_interface = Format2ConverterGalaxyInterface() import_options = ImportOptions() import_options.deduplicate_subworkflows = True - as_dict = python_to_workflow( - as_dict, galaxy_interface, workflow_directory=workflow_directory, import_options=import_options - ) + try: + as_dict = python_to_workflow( + as_dict, galaxy_interface, workflow_directory=workflow_directory, import_options=import_options + ) + except yaml.scanner.ScannerError as e: + raise exceptions.MalformedContents(str(e)) return RawWorkflowDescription(as_dict, workflow_path) diff --git a/lib/galaxy_test/api/test_workflows.py b/lib/galaxy_test/api/test_workflows.py index cfb723048934..4c453c4011b7 100644 --- a/lib/galaxy_test/api/test_workflows.py +++ b/lib/galaxy_test/api/test_workflows.py @@ -1,4 +1,5 @@ import base64 +import io import json import os import shutil @@ -7752,6 +7753,11 @@ def test_subworkflow_tags(self): subworkflow = downloaded_workflow["steps"]["1"]["subworkflow"] assert subworkflow["tags"] == [] + def test_upload_malformated_yaml(self): + malformated_yaml = "class: GalaxyWorkflow:\n a-1:()" + r = self._post("workflows", files={"archive_file": io.StringIO(malformated_yaml)}) + assert r.status_code == 400 + class TestAdminWorkflowsApi(BaseWorkflowsApiTestCase): require_admin_user = True