Workflow/State Machine, guard event is triggered with the wrong transition #46381
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
I may be wrong here, but I don't think there is an issue. So when trying to apply the transition, you get a The second parameter of https://github.com/symfony/workflow/blob/5.4/Event/GuardEvent.php
so I believe you need to do something like this to access your message:
Here |
Beta Was this translation helpful? Give feedback.
-
Is my understanding correct that it is expected when you call: That when the guard is triggered and you get the context in the guard function: That the context is an empty array? I think that may be @netstrada's issue. For me it is weird that the GuardEvent has no context but then in the transition function the TransitionEvent does have the context. This may be intentional however? Cheers |
Beta Was this translation helpful? Give feedback.
-
Hello, Your listener is called because after the transition ref: https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Workflow/Workflow.php#L240 You can control what events event ( about
This is done on purpose, to avoid any side effect. The guard must vote with the subject only, not with the context. Context is here only for additional data to be saved. So if you need more context to be able to take a decision, you must attach it to your subject (but it can be volatil data, it does't have to be stored) |
Beta Was this translation helpful? Give feedback.
-
Hi @lyrixx, regarding
I wonder if being able to use context isn't better solution in this case. Because then context is used only within workflow, while with proposed solution it has to be attached to the subject, and often subject is an entity. As result entity gets properties which are used solely for making decision in workflow, and it is tightly bound through these properties to the specific component of the framework. Context is allowed for other Is it possible to consider reintroducing context in guard events? I could create PR. |
Beta Was this translation helpful? Give feedback.
Hello,
Your listener is called because after the transition
complete_payment
is applied, the workflow searches for new available available transitions, in order to dispatch a new event.ref: https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/Workflow/Workflow.php#L240
You can control what events event (
workflow.announce
) are dispatched thanks to the configurationabout
This is done on purpose, to avoid any side effect. The guard must vote with the subject only, not with the context. Context is here only for additional data to be saved. So if you n…