pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.5k stars 525 forks source link

State names being split #425

Closed abhishek-sharma97 closed 4 years ago

abhishek-sharma97 commented 4 years ago

Using transitions 0.8.1 While creating a HeirarchicalMachine with states and transitions having "_" in the name, the split function is just picking up the first substring after the split and giving KeyError stating the substring is not found in the states dictionary Any particular reason for adding this split? This was working perfectly with 0.7.2.

states = [
        {"name": "null"},
        {"name": "app_draft"},
        {"name": "validation_pending"},
        {"name": "validation_failed"},
        {"name": "ready"},
    ]

On further digging, realised that its happening here: https://github.com/pytransitions/transitions/blob/ddd0709af13e007c9cd8dd56fda77dbc51f90f60/transitions/extensions/nesting.py#L343

Is it because of the counter addition functionality added for children states? Any suggestions and answers will be really appreciated.

potens1 commented 4 years ago

Hello,

I bumped into the same problem (reusing old code with new lib version), An easy fix you can use is to change the separator with

NestedState.separator = '↦'

Hope it helps

PS: I think this will bite more than one developer...

abhishek-sharma97 commented 4 years ago

This sorted the issue, Thanks!

aleneum commented 4 years ago

Using underscores in state names AND as a separator used to somewhat work in HierarchicalStateMachine before 0.8.0. Back then the HSM used a 'flatten' strategy with one state dictionary. But this also had its limitation: Having a state State_A with a child State_1 would collide with with a State with a child A_State_1 since both names combined are equal. I will add a passage in the documentation to clarify that having a seperator in the state name is not supported any longer.