Skip to content

Commit

Permalink
Process: Fix incorrect overriding of transition_failed
Browse files Browse the repository at this point in the history
The `Process` class intended to override the `transition_failed` method
of the `StateMachine` base class, but accidentally implemented the
method `transition_excepted`, which was therefore never called.
  • Loading branch information
sphuber committed Oct 13, 2022
1 parent 3b9d39f commit 84ab1de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
12 changes: 5 additions & 7 deletions src/plumpy/base/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,14 @@ def transition_to(self, new_state: Union[Hashable, State, Type[State]], *args: A
self._transition_failing = False
self._transitioning = False

@staticmethod
def transition_failed(
initial_state: Hashable, final_state: Hashable, exception: Exception, trace: TracebackType
def transition_failed( # pylint: disable=no-self-use
self, initial_state: Hashable, final_state: Hashable, exception: Exception, trace: TracebackType
) -> None:
"""
Called when a state transitions fails. This method can be overwritten
to change the default behaviour which is to raise the exception.
"""Called when a state transitions fails.
:param exception: The transition failed exception
This method can be overwritten to change the default behaviour which is to raise the exception.
:param exception: The transition failed exception.
"""
raise exception.with_traceback(trace)

Expand Down
4 changes: 2 additions & 2 deletions src/plumpy/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,8 @@ def close(self) -> None:

# region State related methods

def transition_excepted(
self, _initial_state: Any, final_state: process_states.ProcessState, exception: Exception, trace: TracebackType
def transition_failed(
self, initial_state: Hashable, final_state: Hashable, exception: Exception, trace: TracebackType
) -> None:
# If we are creating, then reraise instead of failing.
if final_state == process_states.ProcessState.CREATED:
Expand Down
7 changes: 3 additions & 4 deletions test/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,9 @@ def test_forget_to_call_parent(self):
proc.execute()

def test_forget_to_call_parent_kill(self):
with self.assertRaises(AssertionError):
proc = ForgetToCallParent('kill')
proc.kill()
proc.execute()
proc = ForgetToCallParent('kill')
proc.kill()
assert proc.is_excepted

def test_pid(self):
# Test auto generation of pid
Expand Down

0 comments on commit 84ab1de

Please sign in to comment.