Skip to content

Commit

Permalink
Merge pull request galaxyproject#18734 from mvdbeek/improve_yaml_exce…
Browse files Browse the repository at this point in the history
…ption_reporting

[24.1] Catch and display exceptions when importing malformatted yaml workflows
  • Loading branch information
jmchilton authored Aug 24, 2024
2 parents a2c396f + a2c3040 commit 5d5f537
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/galaxy/managers/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)

import sqlalchemy
import yaml
from gxformat2 import (
from_galaxy_native,
ImporterGalaxyInterface,
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions lib/galaxy_test/api/test_workflows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import io
import json
import os
import shutil
Expand Down Expand Up @@ -7830,6 +7831,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
Expand Down

0 comments on commit 5d5f537

Please sign in to comment.