Skip to content

Commit

Permalink
allow workflow config to unset global events config (#6518)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomekTrzeciak authored Feb 14, 2025
1 parent c8db7d1 commit aad39a9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes.d/6518.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow setting empty values in `flow.cylc[scheduler][events]` to override the global configuration.
6 changes: 5 additions & 1 deletion cylc/flow/parsec/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
from optparse import Values


class DefaultList(list):
"""List subclass to indicate unassigned list values in expanded config."""


class ParsecConfig:
"""Object wrapper for parsec functions."""

Expand Down Expand Up @@ -112,7 +116,7 @@ def expand(self) -> None:
else:
if node.default == ConfigNode.UNSET:
if node.vdr and node.vdr.endswith('_LIST'):
defs[node.name] = []
defs[node.name] = DefaultList()
else:
defs[node.name] = None
else:
Expand Down
7 changes: 4 additions & 3 deletions cylc/flow/workflow_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
from cylc.flow.hostuserutil import get_host, get_user
from cylc.flow.log_diagnosis import run_reftest
from cylc.flow.parsec.config import DefaultList
from cylc.flow.subprocctx import SubProcContext

if TYPE_CHECKING:
Expand Down Expand Up @@ -198,7 +199,7 @@ def process_mail_footer(
"""
try:
return (mail_footer_tmpl + '\n') % template_vars
except (KeyError, ValueError):
except (KeyError, TypeError, ValueError):
LOG.warning(
f'Ignoring bad mail footer template: {mail_footer_tmpl}'
)
Expand Down Expand Up @@ -235,7 +236,7 @@ def get_events_conf(
glbl_cfg().get(['scheduler', 'mail'])
):
value = getter.get(key)
if value is not None and value != []:
if value is not None and not isinstance(value, DefaultList):
return value
return default

Expand Down Expand Up @@ -328,7 +329,7 @@ def _run_event_custom_handlers(self, schd, template_variables, event):
cmd_key = ('%s-%02d' % (self.WORKFLOW_EVENT_HANDLER, i), event)
try:
cmd = handler % (template_variables)
except KeyError as exc:
except (KeyError, TypeError, ValueError) as exc:
message = f'{cmd_key} bad template: {handler}\n{exc}'
LOG.error(message)
continue
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_workflow_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
('handlers', True, True, ['stall']),
('handlers', False, True, None),
('handlers', False, False, None),
('mail events', True, True, []),
('mail events', False, True, ['abort']),
('mail events', False, False, None),
('from', True, True, 'docklands@railway'),
('from', False, True, 'highway@mixture'),
('from', False, False, None),
Expand All @@ -55,13 +58,14 @@ def test_get_events_handler(
from = highway@mixture
[[events]]
abort on workflow timeout = True
mail events = abort
'''
)

config = SimpleNamespace()
config.cfg = {
'scheduler': {
'events': {'handlers': ['stall']},
'events': {'handlers': ['stall'], 'mail events': []},
'mail': {'from': 'docklands@railway'},
} if workflow_cfg else {'events': {}}
}
Expand Down

0 comments on commit aad39a9

Please sign in to comment.