You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
validators in a dict/JSON transition definition is silently dropped #628
validators in a dict/JSON transition definition is silently dropped
Summary
create_machine_class_from_definition (the statemachine.io dict adapter) threads cond, unless, on, before, and after from each transition definition into Transition(...), but not validators. As a result, a validators entry in a dict- or JSON-defined machine is silently ignored — it never reaches the Transition, so it never runs at send().
Separately, the TransitionDict TypedDict declares validators: bool, which is the wrong type — it should be the same callback-spec union as cond/unless (str | ActionProtocol | Sequence[...]).
This matters because, per the docs, validators are the intended channel for explicit transition rejection with a reason (raise to abort), distinct from cond/unless (silent disallow). Users building machines from dict/JSON definitions currently have no way to attach that channel.
The validators callbacks supplied in the definition are materialized onto the Transition (which already accepts validators= in its constructor) and run at send(), exactly like cond/unless/on/before/after.
Environment
python-statemachine main (also reproduces on 3.1.2)
The fix is a one-line addition to transition_kwargs plus a TypedDict type correction.
Hi @csentis, thanks for the detailed report and reproduction. Fixed on develop in 3c6cb7b (your PR #629, brought in via cherry-pick with your authorship preserved). The validators entry is now threaded into Transition(...) alongside cond/unless/on/before/after, and the TransitionDict type was corrected to the callback-spec union.
Note the code moved during a refactor of the io/ module: the change landed in the new statemachine/io/class_factory.py rather than statemachine/io/__init__.py. Your regression test came along too.
Activity
csentis commentedon Jun 13, 2026
Cp. PR #629
fgmacedo commentedon Jun 17, 2026
Hi @csentis, thanks for the detailed report and reproduction. Fixed on
developin 3c6cb7b (your PR #629, brought in via cherry-pick with your authorship preserved). Thevalidatorsentry is now threaded intoTransition(...)alongsidecond/unless/on/before/after, and theTransitionDicttype was corrected to the callback-spec union.Note the code moved during a refactor of the
io/module: the change landed in the newstatemachine/io/class_factory.pyrather thanstatemachine/io/__init__.py. Your regression test came along too.Closing as resolved. Thanks again!