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

allow workflow config to unset global events config #6518

Merged
merged 5 commits into from
Feb 14, 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/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:
Copy link
Member

Choose a reason for hiding this comment

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

Think this could be simplified to

Suggested change
except (KeyError, TypeError, ValueError) as exc:
except Exception 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
Loading