Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume task parameters with underscores to be strings. #6571

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes.d/6571.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disabled PEP-515-style integer coercion of task parameters containing underscores (e.g. `084_132` was becoming `84132`). This fix returns older behaviour seen in Cylc 7.
1 change: 0 additions & 1 deletion cylc/flow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ def __init__(

# parameter values and templates are normally needed together.
self.parameters = (parameter_values, parameter_templates)

LOG.debug("Expanding [runtime] namespace lists and parameters")

# Set default parameter expansion templates if necessary.
Expand Down
16 changes: 14 additions & 2 deletions cylc/flow/parsec/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,22 +1007,30 @@ def coerce_parameter_list(cls, value, keys):
>>> CylcConfigValidator.coerce_parameter_list('a, b, c', None)
['a', 'b', 'c']

>>> CylcConfigValidator.coerce_parameter_list('084_132', None)
['084_132']

>>> CylcConfigValidator.coerce_parameter_list('072, a', None)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Fixes a coverage hole.

['072', 'a']
"""
items = []
can_only_be = None # A flag to prevent mixing str and int range
for item in cls.strip_and_unquote_list(keys, value):
values = cls.parse_int_range(item)
if values is not None:
if can_only_be == str:
if can_only_be is str:
raise IllegalValueError(
'parameter', keys, value, 'mixing int range and str')
can_only_be = int
items.extend(values)
elif cls._REC_NAME_SUFFIX.match(item): # noqa: SIM106
try:
if '_' in item:
# Disable PEP-515 int coercion; go to except block:
raise ValueError()
int(item)
except ValueError:
if can_only_be == int:
if can_only_be is int:
raise IllegalValueError(
'parameter',
keys,
Expand All @@ -1034,6 +1042,10 @@ def coerce_parameter_list(cls, value, keys):
else:
raise IllegalValueError(
'parameter', keys, value, '%s: bad value' % item)

if can_only_be is str:
return items

try:
return [int(item) for item in items]
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/parsec/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def test_coerce_parameter_list():
('-15, -10, -5, -1..1', [-15, -10, -5, -1, 0, 1])]:
assert validator.coerce_parameter_list(value, ['whatever']) == result
# The bad
for value in ['foo/bar', 'p1, 1..10', '2..3, 4, p']:
for value in ['foo/bar', 'p1, 1..10', '2..3, 4, p', 'x:,']:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix a coverage hole.

with pytest.raises(IllegalValueError):
validator.coerce_parameter_list(value, ['whatever'])

Expand Down
Loading