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

WorkChains: Raise if predicate if_/while_ does not return boolean #5924

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Mar 9, 2023

Fixes #5477

Before the conditionals created by the if_ and while_ constructs would enter their body as long as the predicate returned anything that was truthy. This could lead to unexpected behavior. For example, if a user tried to abort a workchain from the predicate of a while-loop by returning an ExitCode instance, the while stepper would accept the exit code as truthy and continue the loop.

To prevent this, the conditionals will now raise a TypeError whenever the value returned by the predicate is not a boolean. Since this logic was added in plumpy==0.21.4 the dependency requirement is updated.

Before the conditionals created by the `if_` and `while_` constructs
would enter their body as long as the predicate returned anything that
was truthy. This could lead to unexpected behavior. For example, if a
user tried to abort a workchain from the predicate of a while-loop by
returning an `ExitCode` instance, the while stepper would accept the
exit code as truthy and continue the loop.

To prevent this, the conditionals will now raise a `TypeError` whenever
the value returned by the predicate is not a boolean. Since this logic
was added in `plumpy==0.21.4` the dependency requirement is updated.
@sphuber sphuber requested a review from unkcpz March 9, 2023 14:00
Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

Looks all good, thanks!

@sphuber sphuber merged commit f7d7a4f into aiidateam:main Mar 9, 2023
@sphuber sphuber deleted the fix/5477/check-return-type-while-if branch March 9, 2023 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WorkChain: return exit_code in while_ will not terminate the workchain.
2 participants