Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for missing workflow inputs #842

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions beeflow/common/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ def resolve_input(input_, type_):
"""
# Use parsed input parameter for input value if it exists
input_id = _shortname(input_.id)
if input_id not in self.params:
return None
if not isinstance(self.params[input_id], type_map[type_]):
value = self.params[input_id] if input_id in self.params else input_.default
if value is None:
raise CwlParseError(f"input {input_id} is missing from workflow job file")
if not isinstance(value, type_map[type_]):
raise CwlParseError("Input/param types do not match: "
f"{input_id}/{self.params[input_id]}")
return self.params[input_id]
f"{input_id}/{value}")
return value

workflow_name = os.path.basename(cwl_path).split(".")[0]
workflow_inputs = {InputParameter(_shortname(input_.id), input_.type,
Expand Down Expand Up @@ -245,6 +246,9 @@ def parse_step_outputs(cwl_out, step_outputs, stdout, stderr):
:type stderr: str or None
:rtype: list of StepOutput
"""
if not cwl_out:
return []

out_short = list(map(_shortname, cwl_out))
short_id = out_short[0].split("/")[0]
# Inline step outputs already have short_id+"/" prepended
Expand Down
4 changes: 3 additions & 1 deletion beeflow/tests/cf.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class: Workflow
cwlVersion: v1.0

inputs:
infile: File
infile:
type: File
default: 'infile'

outputs:
clamr_dir:
Expand Down
14 changes: 12 additions & 2 deletions beeflow/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pathlib import Path
import unittest
from beeflow.common.parser import CwlParser
from beeflow.common.parser import CwlParser, CwlParseError
from beeflow.common.wf_data import (generate_workflow_id, Workflow, Task, Hint,
StepInput, StepOutput, InputParameter, OutputParameter)

Expand Down Expand Up @@ -76,6 +76,16 @@ def test_parse_workflow_no_job(self):
for task in tasks:
self.assertEqual(task.workflow_id, workflow_id)

def test_parse_workflow_missing_input(self):
"""Test parsing a workflow with a missing input value in the input file."""
cwl_wf_file = find('ci/test_workflows/missing-input/workflow.cwl')
cwl_job_yaml = find('ci/test_workflows/missing-input/input.yml')

workflow_id = generate_workflow_id()

with self.assertRaises(CwlParseError):
_, _ = self.parser.parse_workflow(workflow_id, cwl_wf_file, cwl_job_yaml)


WORKFLOW_GOLD_SCRIPT = Workflow(
name='clamr_wf',
Expand Down Expand Up @@ -247,7 +257,7 @@ def test_parse_workflow_no_job(self):
name='cf',
hints=[],
requirements=[],
inputs={InputParameter(id='infile', type='File', value=None)},
inputs={InputParameter(id='infile', type='File', value='infile')},
outputs={OutputParameter(id='ffmpeg_movie', type='File', value=None, source='ffmpeg/outfile'),
OutputParameter(id='clamr_dir', type='File', value=None, source='clamr/outfile')},
workflow_id=generate_workflow_id())
Expand Down
1 change: 1 addition & 0 deletions ci/test_workflows/missing-input/input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b: 232
20 changes: 20 additions & 0 deletions ci/test_workflows/missing-input/workflow.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class: Workflow
cwlVersion: v1.2

inputs:
a: int
outputs: {}

steps:
step0:
run:
class: CommandLineTool
baseCommand: echo
inputs:
a:
type: int
inputBinding: {}
outputs: []
in:
a: a
out: []