Skip to content

Commit

Permalink
Allow setting default value for required parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Nov 28, 2024
1 parent a648915 commit 40a8bb1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
13 changes: 8 additions & 5 deletions lib/galaxy/workflow/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,12 +1260,15 @@ def get_inputs(self):

when_true = ConditionalWhen()
when_true.value = "true"
when_true.inputs = {}
when_true.inputs["default"] = specify_default_cond
when_true.inputs = {"default": specify_default_cond}

when_false = ConditionalWhen()
when_false.value = "false"
when_false.inputs = {}
# This is only present for backwards compatibility,
# We don't need this conditional since you can set
# a default value for optional and required parameters.
# TODO: version the state and upgrade it to a simpler version
when_false.inputs = {"default": specify_default_cond}

optional_cases = [when_true, when_false]
optional_cond.cases = optional_cases
Expand Down Expand Up @@ -1504,6 +1507,7 @@ def get_runtime_inputs(self, step, connections: Optional[Iterable[WorkflowStepCo
parameter_def = self._parse_state_into_dict()
parameter_type = parameter_def["parameter_type"]
optional = parameter_def["optional"]
default_value_set = "default" in parameter_def
default_value = parameter_def.get("default", self.default_default_value)
if parameter_type not in ["text", "boolean", "integer", "float", "color", "directory_uri"]:
raise ValueError("Invalid parameter type for workflow parameters encountered.")
Expand Down Expand Up @@ -1557,7 +1561,7 @@ def _parameter_def_list_to_options(parameter_value):

parameter_class = parameter_types[client_parameter_type]

if optional:
if default_value_set:
if client_parameter_type == "select":
parameter_kwds["selected"] = default_value
else:
Expand Down Expand Up @@ -1633,7 +1637,6 @@ def step_state_to_tool_state(self, state):
if "default" in state:
default_set = True
default_value = state["default"]
state["optional"] = True
multiple = state.get("multiple")
source_validators = state.get("validators")
restrictions = state.get("restrictions")
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/workflow/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ def set_outputs_for_input(
if self.inputs_by_step_id:
step_id = step.id
if step_id not in self.inputs_by_step_id and "output" not in outputs:
default_value = step.input_default_value
if default_value or step.input_optional:
default_value = step.get_input_default_value(modules.NO_REPLACEMENT)
if default_value is not modules.NO_REPLACEMENT:
outputs["output"] = default_value
else:
log.error(f"{step.log_str()} not found in inputs_step_id {self.inputs_by_step_id}")
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy_test/api/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3212,7 +3212,7 @@ def test_export_invocation_ro_crate_adv(self):
""",
test_data="""
num_lines_param:
type: int
type: raw
value: 2
input collection 1:
collection_type: list
Expand Down Expand Up @@ -7034,12 +7034,14 @@ def test_subworkflow_import_order_maintained(self, history_id):
outer_input_1:
type: int
default: 1
optional: true
position:
left: 0
top: 0
outer_input_2:
type: int
default: 2
optional: true
position:
left: 100
top: 0
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy_test/base/workflow_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@
int_input:
type: integer
default: 3
optional: true
steps:
random:
tool_id: random_lines1
Expand Down

0 comments on commit 40a8bb1

Please sign in to comment.