python-statemachine
python-statemachine copied to clipboard
on_enter_ not executed for initial state
- 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.
In my opinion, other option is to define a temporary State0 and perform the transition to a on_enter_* state.
I suggest to close this issue.
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()
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.
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.