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

Fix bug with task name as substring of task name. #4426

Merged
merged 6 commits into from
Sep 23, 2021
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ cli options.

### Fixes

[#4426](https://github.com/cylc/cylc-flow/pull/4426) -
Fix bug when a conditional expression in the graph contains one task name that
is a substring of another.

[#4341](https://github.com/cylc/cylc-flow/pull/4341) -
Remove obsolete Cylc 7 `[scheduling]spawn to max active cycle points` config.

Expand Down
26 changes: 23 additions & 3 deletions cylc/flow/prerequisite.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""Functionality for expressing and evaluating logical triggers."""

import math
import re

from cylc.flow import ID_DELIM
from cylc.flow.cycling.loader import get_point
Expand Down Expand Up @@ -115,16 +116,35 @@ def get_raw_conditional_expression(self):

def set_condition(self, expr):
"""Set the conditional expression for this prerequisite.

Resets the cached state (self._all_satisfied).

Examples:
# GH #3644 construct conditional expression when one task name
# is a substring of another: foo | xfoo => bar.
# Add 'foo' to the 'satisfied' dict before 'xfoo'.
>>> preq = Prerequisite(1)
>>> preq.satisfied = {
... ('foo', '1', 'succeeded'): False,
... ('xfoo', '1', 'succeeded'): False
... }
>>> preq.set_condition("foo.1 succeeded|xfoo.1 succeeded")
>>> expr = preq.conditional_expression
>>> expr.split('|') # doctest: +NORMALIZE_WHITESPACE
['bool(self.satisfied[("foo", "1", "succeeded")])',
'bool(self.satisfied[("xfoo", "1", "succeeded")])']

"""
self._all_satisfied = None
if '|' in expr:
# Make a Python expression so we can eval() the logic.
for message in self.satisfied:
expr = expr.replace(self.MESSAGE_TEMPLATE % message,
self.SATISFIED_TEMPLATE % message)
# Use '\b' in case one task name is a substring of another
# and escape special chars ('.', timezone '+') in task IDs.
expr = re.sub(
fr"\b{re.escape(self.MESSAGE_TEMPLATE % message)}\b",
self.SATISFIED_TEMPLATE % message,
expr
)
self.conditional_expression = expr

def is_satisfied(self):
Expand Down