Skip to content

Conditional transition evaluation order is confusing #541

@emptierset

Description

@emptierset

From https://python-statemachine.readthedocs.io/en/latest/guards.html#conditions:

This feature allows for multiple transitions on the same Event, with each Transition checked in the order they are declared.

I was actually about to file a bug report, but rereading this passage made me try something unintuitive that appears to have answered my question. Basically, it seems a bit confusing (and worth documenting more specifically) that what matters for a particular Event is the order in which the various transitions are defined elsewhere, rather than their order in the Event's TransitionList. For example:

last_thing_to_check = s.FOO.to(s.QUX)

second_thing_to_check = s.FOO.to(s.BAZ)

@second_thing_to_check.cond
def second_thing_to_check_cond(self):
    # ...

first_thing_to_check = s.FOO.to(s.BAR)

@first_thing_to_check.cond
def first_thing_to_check_cond(self):
    # ...

go_somewhere = first_thing_to_check | second_thing_to_check | last_thing_to_check

I was struggling to figure out why go_somewhere was just doing last_thing_to_check without testing any of the conditional transitions. I'm not sure whether this is a bug, but I found the behavior very surprising. It might be worth documenting somewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions