Skip to content

Commit

Permalink
Progress on repeat validation...
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jul 25, 2024
1 parent 9559f92 commit 06afe0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/galaxy/tool_util/parameters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions test/unit/tool_util/parameter_specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ gx_repeat_data:
- parameter: []
- parameter:
- { data_parameter: {src: hda, id: abcdabcd} }
# an empty repeat is fine
- {}
request_invalid:
- parameter: [{}, {}]
- parameter: [{}]
Expand Down

0 comments on commit 06afe0a

Please sign in to comment.