Skip to content

fix(io): materialize transition validators from dict definitions#629

Open
csentis wants to merge 1 commit into
fgmacedo:developfrom
csentis:fix/io-materialize-validators
Open

fix(io): materialize transition validators from dict definitions#629
csentis wants to merge 1 commit into
fgmacedo:developfrom
csentis:fix/io-materialize-validators

Conversation

@csentis

@csentis csentis commented Jun 13, 2026

Copy link
Copy Markdown

What

create_machine_class_from_definition builds each Transition with cond, unless, on, before, and after from the definition — but dropped validators. So a validators entry in a dict/JSON definition was silently ignored and never ran at send(). The TransitionDict TypedDict also mistyped validators as bool.

This PR:

  • threads validators through to Transition(...) in create_machine_class_from_definition;
  • corrects the TransitionDict.validators annotation to the same callback-spec union as cond/unless;
  • adds a regression test (tests/test_io.py::TestTransitionValidators) proving a definition-supplied validator runs and aborts on send() (the test fails without the production change).

Why

Transition.__init__ already accepts validators=; only the dict adapter wasn't passing it. Validators are the documented explicit-rejection channel (raise with a reason) — without this, dict/JSON-defined machines can't use it.

Notes

  • Two-line production change + type fix; no behavior change for definitions that don't set validators.
  • ruff check clean; pytest tests/test_io.py green (4 passed).

create_machine_class_from_definition threaded cond/unless/on/before/after
into Transition(), but dropped validators — so a 'validators' entry in a
dict/JSON definition was silently ignored and never ran at send(). The
TransitionDict TypedDict also mistyped validators as bool.

Pass validators through to Transition() and fix the type to the same
callback-spec union as cond/unless. Adds a regression test proving a
definition-supplied validator runs (and aborts) on send().

Closes #<issue>.

Signed-off-by: Christian Sentis <christian.sentis@icloud.com>
@sonarqubecloud

Copy link
Copy Markdown

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

Successfully merging this pull request may close these issues.

1 participant