Skip to content

Commit aad39a9

Browse files
allow workflow config to unset global events config (#6518)
1 parent c8db7d1 commit aad39a9

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

changes.d/6518.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow setting empty values in `flow.cylc[scheduler][events]` to override the global configuration.

cylc/flow/parsec/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
from optparse import Values
3636

3737

38+
class DefaultList(list):
39+
"""List subclass to indicate unassigned list values in expanded config."""
40+
41+
3842
class ParsecConfig:
3943
"""Object wrapper for parsec functions."""
4044

@@ -112,7 +116,7 @@ def expand(self) -> None:
112116
else:
113117
if node.default == ConfigNode.UNSET:
114118
if node.vdr and node.vdr.endswith('_LIST'):
115-
defs[node.name] = []
119+
defs[node.name] = DefaultList()
116120
else:
117121
defs[node.name] = None
118122
else:

cylc/flow/workflow_events.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
2525
from cylc.flow.hostuserutil import get_host, get_user
2626
from cylc.flow.log_diagnosis import run_reftest
27+
from cylc.flow.parsec.config import DefaultList
2728
from cylc.flow.subprocctx import SubProcContext
2829

2930
if TYPE_CHECKING:
@@ -198,7 +199,7 @@ def process_mail_footer(
198199
"""
199200
try:
200201
return (mail_footer_tmpl + '\n') % template_vars
201-
except (KeyError, ValueError):
202+
except (KeyError, TypeError, ValueError):
202203
LOG.warning(
203204
f'Ignoring bad mail footer template: {mail_footer_tmpl}'
204205
)
@@ -235,7 +236,7 @@ def get_events_conf(
235236
glbl_cfg().get(['scheduler', 'mail'])
236237
):
237238
value = getter.get(key)
238-
if value is not None and value != []:
239+
if value is not None and not isinstance(value, DefaultList):
239240
return value
240241
return default
241242

@@ -328,7 +329,7 @@ def _run_event_custom_handlers(self, schd, template_variables, event):
328329
cmd_key = ('%s-%02d' % (self.WORKFLOW_EVENT_HANDLER, i), event)
329330
try:
330331
cmd = handler % (template_variables)
331-
except KeyError as exc:
332+
except (KeyError, TypeError, ValueError) as exc:
332333
message = f'{cmd_key} bad template: {handler}\n{exc}'
333334
LOG.error(message)
334335
continue

tests/unit/test_workflow_events.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
('handlers', True, True, ['stall']),
3535
('handlers', False, True, None),
3636
('handlers', False, False, None),
37+
('mail events', True, True, []),
38+
('mail events', False, True, ['abort']),
39+
('mail events', False, False, None),
3740
('from', True, True, 'docklands@railway'),
3841
('from', False, True, 'highway@mixture'),
3942
('from', False, False, None),
@@ -55,13 +58,14 @@ def test_get_events_handler(
5558
from = highway@mixture
5659
[[events]]
5760
abort on workflow timeout = True
61+
mail events = abort
5862
'''
5963
)
6064

6165
config = SimpleNamespace()
6266
config.cfg = {
6367
'scheduler': {
64-
'events': {'handlers': ['stall']},
68+
'events': {'handlers': ['stall'], 'mail events': []},
6569
'mail': {'from': 'docklands@railway'},
6670
} if workflow_cfg else {'events': {}}
6771
}

0 commit comments

Comments
 (0)