diff --git a/lib/galaxy/tool_util/parameters/models.py b/lib/galaxy/tool_util/parameters/models.py index ab5d2fea5f0d..2cb05b1bdad1 100644 --- a/lib/galaxy/tool_util/parameters/models.py +++ b/lib/galaxy/tool_util/parameters/models.py @@ -601,18 +601,30 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam self.parameters, f"Repeat_{self.name}", state_representation ) + if self.request_requires_value: + initialize_repeat = ... + else: + initialize_repeat = None + class RepeatType(RootModel): - root: List[instance_class] = Field(..., min_length=self.min, max_length=self.max) # type: ignore[valid-type] + root: List[instance_class] = Field(initialize_repeat, min_length=self.min, max_length=self.max) # type: ignore[valid-type] return DynamicModelInformation( self.name, - (RepeatType, ...), + (RepeatType, initialize_repeat), {}, ) @property def request_requires_value(self) -> bool: - return True # TODO: + if self.min is None or self.min == 0: + return False + # so we know we need at least one value, but maybe none of the parameters in the list + # are required + for parameter in self.parameters: + if parameter.request_requires_value: + return True + return False class SectionParameterModel(BaseGalaxyToolParameterModelDefinition): diff --git a/test/unit/tool_util/parameter_specification.yml b/test/unit/tool_util/parameter_specification.yml index ed1cc5981332..31580d3422d4 100644 --- a/test/unit/tool_util/parameter_specification.yml +++ b/test/unit/tool_util/parameter_specification.yml @@ -558,6 +558,8 @@ gx_repeat_data: - parameter: [] - parameter: - { data_parameter: {src: hda, id: abcdabcd} } + # an empty repeat is fine + - {} request_invalid: - parameter: [{}, {}] - parameter: [{}]