Skip to content

Commit

Permalink
Merge pull request #17983 from mvdbeek/fix_LengthValidator
Browse files Browse the repository at this point in the history
[24.0] Fix `LengthValidator` if no value passed
  • Loading branch information
mvdbeek authored Apr 15, 2024
2 parents eb472db + 92dfa46 commit bb40376
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/galaxy/tools/parameters/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def __init__(self, message, length_min, length_max, negate):
super().__init__(message, range_min=length_min, range_max=length_max, negate=negate)

def validate(self, value, trans=None):
super().validate(len(value), trans)
if value is None:
raise ValueError("No value provided")
super().validate(len(value) if value else 0, trans)


class DatasetOkValidator(Validator):
Expand Down
8 changes: 8 additions & 0 deletions test/unit/app/tools/test_parameter_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ def test_LengthValidator(self):
p.validate("bar")
p.validate("f")
p.validate("foobarbaz")
p = self._parameter_for(
xml="""
<param name="blah" type="text" optional="false">
<validator type="length" min="2" max="8"/>
</param>"""
)
with self.assertRaisesRegex(ValueError, "No value provided"):
p.validate(None)

def test_InRangeValidator(self):
p = self._parameter_for(
Expand Down

0 comments on commit bb40376

Please sign in to comment.