diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 76f53e4d3ab..36618d478a5 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -302,12 +302,16 @@ class SimpleTextToolParameter(ToolParameter): def __init__(self, tool, input_source): input_source = ensure_input_source(input_source) super().__init__(tool, input_source) - self.value = '' + self.optional = input_source.get_bool('optional', False) + if self.optional: + self.value = None + else: + self.value = '' def to_json(self, value, app, use_security): """Convert a value to a string representation suitable for persisting""" if value is None: - rval = '' + rval = '' if not self.optional else None else: rval = unicodify(value) return rval @@ -346,6 +350,7 @@ class TextToolParameter(SimpleTextToolParameter): d = super().to_dict(trans) d['area'] = self.area d['datalist'] = self.datalist + d['optional'] = self.optional return d diff --git a/lib/galaxy/tools/parameters/wrapped_json.py b/lib/galaxy/tools/parameters/wrapped_json.py index 9ae1882e751..f112bde13d1 100644 --- a/lib/galaxy/tools/parameters/wrapped_json.py +++ b/lib/galaxy/tools/parameters/wrapped_json.py @@ -86,7 +86,10 @@ def _json_wrap_input(input, value_wrapper, profile, handle_files="skip"): return SKIP_INPUT raise NotImplementedError() elif input_type in ["text", "color", "hidden"]: - json_value = _cast_if_not_none(value_wrapper, str) + if getattr(input, "optional", False) and value_wrapper is not None and value_wrapper.value is None: + json_value = None + else: + json_value = _cast_if_not_none(value_wrapper, str) elif input_type == "float": json_value = _cast_if_not_none(value_wrapper, float, empty_to_none=True) elif input_type == "integer": diff --git a/test/functional/tools/expression_null_handling_float.xml b/test/functional/tools/expression_null_handling_float.xml new file mode 100644 index 00000000000..ec8139de59f --- /dev/null +++ b/test/functional/tools/expression_null_handling_float.xml @@ -0,0 +1,22 @@ + + + {return {'float_out': $job.float_input};} + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/expression_null_handling_integer.xml b/test/functional/tools/expression_null_handling_integer.xml new file mode 100644 index 00000000000..d6dbc1e2abc --- /dev/null +++ b/test/functional/tools/expression_null_handling_integer.xml @@ -0,0 +1,22 @@ + + + {return {'int_out': $job.int_input};} + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/expression_null_handling_text.xml b/test/functional/tools/expression_null_handling_text.xml new file mode 100644 index 00000000000..d29bb731c02 --- /dev/null +++ b/test/functional/tools/expression_null_handling_text.xml @@ -0,0 +1,32 @@ + + + {return {'text_out': $job.text_input};} + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index a634fef6194..98a5907a9c1 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -175,6 +175,9 @@ + + +