aiidateam / plumpy

A python workflows library that supports writing Processes with a well defined set of inputs and outputs that can be strung together.
https://plumpy.readthedocs.io
Other
8 stars 17 forks source link

`StateMachine`: transition directly to excepted if transition failed #240

Closed sphuber closed 2 years ago

sphuber commented 2 years ago

Fixes #219

Before, if a state transition failed a transition to the excepted state would be initiated. However, if the original failure came from a method that would be called in all state transitions, i.e. also when transitioning to the excepted, it would be guaranteed to be hit again. In the second transition failure, the exception would simply be raised again and bubble up.

In the case of a transition failure and so self._transition_failed is set to True, the current state should not be explicitly exited but one should transition straight to the excepted state.

This change now effectively allows the state machine to transition from a FINISHED state to the EXCEPTED state. A process could transition to the FINISHED state and on exiting the FINISHED state, an exception could be raised. In this case the result of the future would already be set, so the on_except method needs to check for this, and when set, first reset the future before setting the exception.

This PR also has two other commits, one with a small feature and a small bug fix.

codecov[bot] commented 2 years ago

Codecov Report

Base: 90.46% // Head: 90.68% // Increases project coverage by +0.23% :tada:

Coverage data is based on head (184ba7a) compared to base (7a218ac). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #240 +/- ## ========================================== + Coverage 90.46% 90.68% +0.23% ========================================== Files 21 21 Lines 2954 2960 +6 ========================================== + Hits 2672 2684 +12 + Misses 282 276 -6 ``` | [Impacted Files](https://codecov.io/gh/aiidateam/plumpy/pull/240?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam) | Coverage Δ | | |---|---|---| | [src/plumpy/base/state\_machine.py](https://codecov.io/gh/aiidateam/plumpy/pull/240/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam#diff-c3JjL3BsdW1weS9iYXNlL3N0YXRlX21hY2hpbmUucHk=) | `86.13% <100.00%> (ø)` | | | [src/plumpy/processes.py](https://codecov.io/gh/aiidateam/plumpy/pull/240/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam#diff-c3JjL3BsdW1weS9wcm9jZXNzZXMucHk=) | `92.41% <100.00%> (+1.04%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.