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

Handle parentheses on RHS of trigger expression #5801

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

MetRonnie
Copy link
Member

@MetRonnie MetRonnie commented Nov 1, 2023

Description

Fix a bug where using parentheses on the right hand side of a graph trigger would cause traceback.

Reproduction

R1 = a => (b & c)
$ cylc validate
Traceback

Traceback (most recent call last):
  File "~/.conda/envs/cylc8/bin/cylc", line 8, in <module>
    sys.exit(main())
  File "~/cylc-flow/cylc/flow/scripts/cylc.py", line 660, in main
    execute_cmd(command, *cmd_args)
  File "~/cylc-flow/cylc/flow/scripts/cylc.py", line 286, in execute_cmd
    entry_point.resolve()(*args)
  File "~/cylc-flow/cylc/flow/terminal.py", line 232, in wrapper
    wrapped_function(*wrapped_args, **wrapped_kwargs)
  File "~/cylc-flow/cylc/flow/scripts/validate.py", line 133, in main
    _main(parser, options, workflow_id)
  File "~/cylc-flow/cylc/flow/scripts/validate.py", line 137, in _main
    asyncio.run(wrapped_main(parser, options, workflow_id))
  File "~/.conda/envs/cylc8/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "~/.conda/envs/cylc8/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "~/cylc-flow/cylc/flow/scripts/validate.py", line 155, in wrapped_main
    cfg = WorkflowConfig(
  File "~/cylc-flow/cylc/flow/config.py", line 518, in __init__
    self.load_graph()
  File "~/cylc-flow/cylc/flow/config.py", line 2123, in load_graph
    parser.parse_graph(graph)
  File "~/cylc-flow/cylc/flow/graph_parser.py", line 465, in parse_graph
    self._proc_dep_pair(pair)
  File "~/cylc-flow/cylc/flow/graph_parser.py", line 627, in _proc_dep_pair
    self._families_all_to_all(expr, rights, info, family_trig_map)
  File "~/cylc-flow/cylc/flow/graph_parser.py", line 671, in _families_all_to_all
    self._compute_triggers(expr, rights, n_expr, n_info)
  File "~/cylc-flow/cylc/flow/graph_parser.py", line 852, in _compute_triggers
    suicide_char, name, output, opt_char = m.groups()  # type: ignore
AttributeError: 'NoneType' object has no attribute 'groups'

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • No dependency changes
  • Tests are included
  • Changelog entry included
  • No docs update needed
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@MetRonnie MetRonnie added the bug Something is wrong :( label Nov 1, 2023
@MetRonnie MetRonnie added this to the cylc-8.2.4 milestone Nov 1, 2023
@MetRonnie MetRonnie self-assigned this Nov 1, 2023
Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

LGTM, and fixes the bug. One general question though:

Given that parentheses are actually meaningless on the right (because OR is not allowed) - which you're handling by stripping them out 👍 - maybe we should just disallow them, and then not have to check for mismatch?

@MetRonnie
Copy link
Member Author

Don't mind too much but IMO this feels like it would be less annoying to users

@wxtim wxtim self-requested a review November 13, 2023 11:30
Comment on lines +522 to +526
mismatch_msg = 'Mismatched parentheses in: "{}"'
if left and left.count("(") != left.count(")"):
raise GraphParseError(mismatch_msg.format(left))
if right.count("(") != right.count(")"):
raise GraphParseError(mismatch_msg.format(right))
Copy link
Member

Choose a reason for hiding this comment

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

I'm outputting the entire thing might be helpful.

Suggested change
mismatch_msg = 'Mismatched parentheses in: "{}"'
if left and left.count("(") != left.count(")"):
raise GraphParseError(mismatch_msg.format(left))
if right.count("(") != right.count(")"):
raise GraphParseError(mismatch_msg.format(right))
mismatch_msg = 'Mismatched parentheses in: "{} => {}"'
if left and left.count("(") != left.count(")"):
raise GraphParseError(mismatch_msg.format(left, right))
if right.count("(") != right.count(")"):
raise GraphParseError(mismatch_msg.format(left, right))

Copy link
Member Author

Choose a reason for hiding this comment

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

Sometimes there will be no arrow involved, however

Copy link
Member

@wxtim wxtim left a comment

Choose a reason for hiding this comment

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

Legit - I've made a suggestion. Take it or leave it (it will break some of your new tests if you take it).

@MetRonnie MetRonnie merged commit d6cc772 into cylc:8.2.x Nov 13, 2023
@MetRonnie MetRonnie deleted the parentheses branch November 13, 2023 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong :(
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants