python-statemachine icon indicating copy to clipboard operation
python-statemachine copied to clipboard

on_enter_ not executed for initial state

Open martinkrammer opened this issue 3 years ago • 3 comments

  • Python State Machine version: 0.8.0
  • Python version: 3.8
  • Operating System: Windows 10

Description

I noticed that the on_enter_* callback is not executed on the state that is declared as initial state.

What I Did

Defined an on_enter_ function callback on the state that is defined as initial state.

martinkrammer avatar Aug 10 '20 09:08 martinkrammer

In my opinion, other option is to define a temporary State0 and perform the transition to a on_enter_* state.

brunolnetto avatar Feb 10 '21 22:02 brunolnetto

I suggest to close this issue.

brunolnetto avatar Feb 10 '21 22:02 brunolnetto

I also got around this with an on_enter_<initial_state>() which transitions to my true actual first state, but it requires a null transition to cause it to execute:

cycle = startup.to.itself() | waiting.to.itself() | driving.to.itself() | obstacle.to.itself() | exit.to.itself()

slowrunner avatar May 31 '22 13:05 slowrunner

There are available workarounds, as OP and @slowrunner suggest. It is up to the current library maintenance team and/or some "community agreement" on issue severity classification.

Consensus allows contribution. Contribution allows feature availability.

brunolnetto avatar Dec 28 '22 13:12 brunolnetto

Just adding info for anyone else who stumbles upon a similar issue and found this GitHub issue. See here for the solution on why the initial state is not entered. HINT: Your class's init method might be overriding the init method of the Statemachine baseclass.

vinkmr avatar Oct 26 '23 11:10 vinkmr