From d24c3cc31830d4906610b88e2c9352179db13fd6 Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:31:41 +0000 Subject: [PATCH] Prevent ill formed set --pre causing scheduler failures. --- cylc/flow/task_pool.py | 18 ++++++++++----- tests/integration/test_task_pool.py | 34 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/cylc/flow/task_pool.py b/cylc/flow/task_pool.py index 39671146247..cc1d6e9c8f0 100644 --- a/cylc/flow/task_pool.py +++ b/cylc/flow/task_pool.py @@ -1715,17 +1715,25 @@ def _standardise_prereqs(self, prereqs: 'List[str]') -> 'List[Tokens]': msg = self.config.get_taskdef( pre['task'] ).outputs[output][0] + cycle=standardise_point_string(pre['cycle']) except KeyError: # The task does not have this output. LOG.warning( f"output {pre.relative_id_with_selectors} not found") continue - _prereqs.append( - pre.duplicate( - task_sel=msg, - cycle=standardise_point_string(pre['cycle']) + except WorkflowConfigError as exc: + # The workflow does not have the task from --pre: + LOG.warning(f'Invalid pre task name set:\n {exc.args[0]}') + except PointParsingError as exc: + # The CP from --pre is invalid: + LOG.warning(f'Invalid pre cycle point set:\n {exc.args[0]}') + else: + _prereqs.append( + pre.duplicate( + task_sel=msg, + cycle=cycle, + ) ) - ) return _prereqs def _standardise_outputs( diff --git a/tests/integration/test_task_pool.py b/tests/integration/test_task_pool.py index 7e205580b98..61780e926a0 100644 --- a/tests/integration/test_task_pool.py +++ b/tests/integration/test_task_pool.py @@ -1383,6 +1383,40 @@ async def test_set_prereqs( assert qux.state.prerequisites_all_satisfied() +async def test_set_bad_prereqs( + flow, + scheduler, + start, + log_filter, +): + """Check manual setting of prerequisites. + + """ + id_ = flow({ + 'scheduler': { + 'allow implicit tasks': 'True', + 'cycle point format': '%Y'}, + 'scheduling': { + 'initial cycle point': '2040', + 'graph': {'R1': "foo => bar"}}, + }) + schd = scheduler(id_) + + def set_prereqs(prereqs): + """Shorthand so only varible under test given as arg""" + schd.pool.set_prereqs_and_outputs( + ["2040/bar"], None, prereqs, ['all']) + + async with start(schd) as log: + # Invalid - task name wildcard: + set_prereqs(["2040/*"]) + assert 'Illegal task name' in log.messages[-1] + + # Invalid cycle point wildcard. + set_prereqs(["*/foo"]) + assert 'Invalid ISO 8601' in log.messages[-1] + + async def test_set_outputs_live( flow, scheduler,