-
Notifications
You must be signed in to change notification settings - Fork 90
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
Fix bugs in cylc broadcast
#5933
Changes from 3 commits
522564c
09766f8
275f93a
aacd390
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed bug in `cylc broadcast` (and the GUI Edit Runtime command) where everything after a `#` character in a setting would be stripped out. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,7 +373,7 @@ def coerce_range(cls, value, keys): | |
return Range((int(min_), int(max_))) | ||
|
||
@classmethod | ||
def coerce_str(cls, value, keys): | ||
def coerce_str(cls, value, keys) -> str: | ||
"""Coerce value to a string. | ||
|
||
Examples: | ||
|
@@ -385,7 +385,7 @@ def coerce_str(cls, value, keys): | |
""" | ||
if isinstance(value, list): | ||
# handle graph string merging | ||
vraw = [] | ||
vraw: List[str] = [] | ||
vals = [value] | ||
while vals: | ||
val = vals.pop() | ||
|
@@ -512,35 +512,36 @@ def parse_int_range(cls, value): | |
return None | ||
|
||
@classmethod | ||
def strip_and_unquote(cls, keys, value): | ||
def strip_and_unquote(cls, keys: List[str], value: str) -> str: | ||
"""Remove leading and trailing spaces and unquote value. | ||
|
||
Args: | ||
keys (list): | ||
keys: | ||
Keys in nested dict that represents the raw configuration. | ||
value (str): | ||
value: | ||
String value in raw configuration. | ||
|
||
Return (str): | ||
Return: | ||
Processed value. | ||
|
||
Examples: | ||
>>> ParsecValidator.strip_and_unquote(None, '" foo "') | ||
'foo' | ||
|
||
""" | ||
for substr, rec in [ | ||
["'''", cls._REC_MULTI_LINE_SINGLE], | ||
['"""', cls._REC_MULTI_LINE_DOUBLE], | ||
['"', cls._REC_DQ_VALUE], | ||
["'", cls._REC_SQ_VALUE]]: | ||
for substr, rec in ( | ||
("'''", cls._REC_MULTI_LINE_SINGLE), | ||
('"""', cls._REC_MULTI_LINE_DOUBLE), | ||
('"', cls._REC_DQ_VALUE), | ||
("'", cls._REC_SQ_VALUE) | ||
): | ||
if value.startswith(substr): | ||
match = rec.match(value) | ||
if not match: | ||
raise IllegalValueError("string", keys, value) | ||
value = match.groups()[0] | ||
break | ||
else: | ||
else: # no break | ||
# unquoted | ||
value = value.split(r'#', 1)[0] | ||
|
||
|
@@ -1136,23 +1137,25 @@ def _coerce_type(cls, value): | |
return val | ||
|
||
|
||
# BACK COMPAT: BroadcastConfigValidator | ||
# The DB at 8.0.x stores Interval values as neither ISO8601 duration | ||
# string or DurationFloat. This has been fixed at 8.1.0, and | ||
# the following class acts as a bridge between fixed and broken. | ||
# url: | ||
# https://github.com/cylc/cylc-flow/pull/5138 | ||
# from: | ||
# 8.0.x | ||
# to: | ||
# 8.1.x | ||
# remove at: | ||
# 8.x | ||
class BroadcastConfigValidator(CylcConfigValidator): | ||
"""Validate and Coerce DB loaded broadcast config to internal objects.""" | ||
def __init__(self): | ||
CylcConfigValidator.__init__(self) | ||
|
||
@classmethod | ||
def coerce_str(cls, value, keys) -> str: | ||
"""Coerce value to a string. | ||
|
||
Examples: | ||
>>> BroadcastConfigValidator.coerce_str('abc#def', None) | ||
MetRonnie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'abc#def' | ||
""" | ||
# Prevent ParsecValidator from assuming '#' means comments; | ||
# '#' has valid uses in shell script such as parameter substitution | ||
if isinstance(value, str) and '#' in value: | ||
value = f'"{value}"' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work if the string is already quoted e.g: $ cylc broadcast one -n root -s 'script="sleep 30 # ja!"'
ERROR: [{'error': {'message': '(type=string) script = ""sleep 30 # ja!""', 'traceback': ['graphql.error.located_error.GraphQLLocatedError: (type=string) script = ""sleep 30 # ja!""\n']}}] Maybe use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return ParsecValidator.coerce_str(value, keys) | ||
|
||
@classmethod | ||
def strip_and_unquote_list(cls, keys, value): | ||
"""Remove leading and trailing spaces and unquote list value. | ||
|
@@ -1177,6 +1180,18 @@ def strip_and_unquote_list(cls, keys, value): | |
value = value.lstrip('[').rstrip(']') | ||
return ParsecValidator.strip_and_unquote_list(keys, value) | ||
|
||
# BACK COMPAT: BroadcastConfigValidator.coerce_interval | ||
# The DB at 8.0.x stores Interval values as neither ISO8601 duration | ||
# string or DurationFloat. This has been fixed at 8.1.0, and | ||
# the following class acts as a bridge between fixed and broken. | ||
# url: | ||
# https://github.com/cylc/cylc-flow/pull/5138 | ||
# from: | ||
# 8.0.x | ||
# to: | ||
# 8.1.x | ||
# remove at: | ||
# 8.x | ||
@classmethod | ||
def coerce_interval(cls, value, keys): | ||
"""Coerce an ISO 8601 interval into seconds. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is overriding a class method from
ParsecValidator