Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triggering/calling events recreates state machine objects but does not maintain state #100

Open
nbxorg opened this issue Aug 8, 2022 · 0 comments

Comments

@nbxorg
Copy link

nbxorg commented Aug 8, 2022

Perhaps I'm misunderstanding the way this FSM library is supposed to work, but I think this is a serious bug:

The StateMachine instance does not maintain state across a state transition.

Infact the example code in README does not validate.

class MyFSM(StateMachine):
    ...
    instance_variable: Optional[str] = None

    @event(None, SomeStateOrOther)
    async def some_event(self, some_arg):
        self.instance_variable = some_arg

 >>> x = MyFSM()
 >>> await x.some_event('hello')
 >>> x.instance_variable
 None

Within coroutines explicitly handled by the event decorator, e.g. during before_transition, after_transition callback execution, accessing self.instance_variable yields the expected response: 'hello'.

But as soon as the execution context of the event has been left, any instance variables (state) we model on the subclass, has been reset to its default. Perhaps the deepcopy does not work as it should with pydantic based instances, or the type inference introspection parts which honestly seems a bit like dark magic, is faulty. I'm unfamiliar with either of these mechanisms so unfortunately not of much help.

Anyhow, it behaves as if the entire StateMachine is recreated after each state transition, but not all the instance member variables are copied over.

I'm currently on Python 3.8 and have tried statesman versions 0.1.0 to 1.0.2post and they all exhibit the same behaviour.

Kind regards,

Yuka Poppe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant