8000 [Workflow] Increase checks to ensure a valid statemachine · Issue #33972 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Workflow] Increase checks to ensure a valid statemachine #33972

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

Closed
holtkamp opened this issue Oct 13, 2019 · 8 comments
Closed

[Workflow] Increase checks to ensure a valid statemachine #33972

holtkamp opened this issue Oct 13, 2019 · 8 comments

Comments

@holtkamp
Copy link
Contributor

Description
Currently it is possible to instantiate an "invalid" StateMachine. It would be nice to have some checks in place to prevent this.

Example
For example:

<?php

use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\StateMachine;
use Symfony\Component\Workflow\Transition;

$states = ['created', 'activated', 'deleted'];
$stateTransitions = [
    new Transition('activate', 'created', 'activated'),
    new Transition('activate', 'created', 'deleted'), //oops, copy-paste mistake: 'activate' should have been 'delete'
];
$definition = new Definition($states, $stateTransitions);
$stateMachine = new StateMachine($definition);

This would result in an "invalid" StateMachine...

Screenshot 2019-10-13 at 19 25 50

Maybe some inspiration can be derived from this implementation of a StateMachine

@OskarStark
Copy link
Contributor

cc @lyrixx

8000

@lyrixx
Copy link
Member
lyrixx commented Oct 21, 2019

Even if there is a typo, this workflow is totally valid. With a state machine, you can have many transitions with the same name and with the same origin.
I don't see how we can validate something here.
I read the code you linked and they put more limitation on a workflow... so we can not grab this code.

@stof
Copy link
Member
stof commented Oct 21, 2019

With a state machine, you can have many transitions with the same name and with the same origin.

are you sure about that for a state machine ? Wouldn't you move you to multiple states ?

IIRC, we allow having the same name with different origins.

I think the main issue here is that the validator is not applied on your definition, so you don't run the checks. These checks are not part of the StateMachine constructor for performance reason: if you define your workflow in the config file, Symfony will run the validation during cache warmup, and so running the validation on each instantiation would be useless overhead.
See https://github.com/symfony/symfony/tree/4.4/src/Symfony/Component/Workflow/Validator for existing definition validators.

@holtkamp
Copy link
Contributor Author
holtkamp commented Oct 21, 2019

are you sure about that for a state machine ? Wouldn't you move you to multiple states ?

Indeed, a (Finite)StateMachine can only be in one state at a certain moment in time. For WorkFlows this rule does not apply...

Also see https://stackoverflow.com/questions/53980748/whats-the-difference-of-petri-nets-and-finite-state-machines

@lyrixx
Copy link
Member
lyrixx commented Oct 21, 2019

are you sure about that for a state machine ? Wouldn't you move you to multiple states ?

You make me doubt :) I guess you are right!

@holtkamp As @stof mentionned, some validator already exist. And this issue is already covered

I think we can close this issue, and there is nothing we can do here since everything already exist.

@holtkamp
Copy link
Contributor Author
holtkamp commented Oct 21, 2019

I think we can close this issue,

Indeed, I was not aware of the StateMachineValidator, maybe it can be documented?

Closing issue!

@lyrixx
Copy link
Member
lyrixx commented Oct 21, 2019

maybe it can be documented?

Good idea. Would you mind open a PR or an issue ?

@holtkamp
Copy link
Contributor Author
holtkamp commented Oct 24, 2019

@lyrixx sure, will give a PR a shot.

I am just in doubt about the proper page to add a "Validation" section:

holtkamp added a commit to holtkamp/symfony-docs that referenced this issue Oct 24, 2019
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Apr 3, 2020
… (holtkamp)

This PR was squashed before being merged into the 4.4 branch (closes #12541).

Discussion
----------

Add section about Workflows and State Machine validation

As suggested in symfony/symfony#33972 (comment)

Commits
-------

ef7ff0b Add section about Workflows and State Machine validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
0