-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Symfony Workflow Component - in some cases event "workflow.[workflow name].entered.[place name]" is being dispatched multiple times for a place even though marking was already in that place #57924
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
Comments
This issue really is causing a problem for me. |
Can you create a small example application that allows to reproduce your issue? |
Hi @xabbuh, The above code examples describe the steps to reproduce the issue. You can either call the command to view the debug dump The App\EventSubscriber\TestEventSubscriber makes the issue visible by dumping some informations about the workflow event on "workflow.reproduce_bug.entered.A" events. As written above in the issue description, the dump gets event subscriber gets executed twice but should be executed only once. Let me know, if you need a docker-compose to easily run the application. |
Hi, have you had the chance to look into that? |
Thanks for this very details bug report ! 💛 I opened a PR to fix my mistake |
…is already in this marking (lyrixx) This PR was merged into the 6.4 branch. Discussion ---------- [Workflow] Fix dispatch of entered event when the subject is already in this marking | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57924 | License | MIT This was wrong: #37813 Commits ------- 7db98c9 [Workflow] Fix dispatch of entered event when the subject is already in this marking
Thanks for the fix! |
Symfony version(s) affected
from 5.2 until 7.2
Description
When working with a workflow that uses two or more places at the same time the "workflow.[workflow name].entered.[place name]" events are being dispatched more than once (when the workflow actually entered a place). At the moment, this events are always dispatched (for all the places, that workflow is currently at) when any place is entered, which in my opinion is wrong and causes problems in workflow executions because listeners for "workflow.[workflow name].entered.[place name]" events get executed more than once.
For example
The marking of workflow "reproduce_bug" just got to ['A' => 1, 'B' => 1] via a transition.
Then the events "workflow.reproduce_bug.entered.A" and "workflow.reproduce_bug.entered.B" where dispatched.
Everything is fine so far.
In the next trasition the marking gets changed from ['A' => 1, 'B' => 1] to ['A' => 1, 'D' => 1] via a transition.
Now the events "workflow.reproduce_bug.entered.D" and "workflow.reproduce_bug.entered.A" are being dispatched.
The event "workflow.reproduce_bug.entered.A" was dispatched again although the marking of the workflow was already at that place and it wasn't changed by the transition (as you can see in the example config below).
This behavior occures since version 5.2 of the Symfony Workflow Component up to current version 7.2.
How to reproduce
Ensure symfony/workflow component is installed
Could be any version >= 5.2 up to 7.2
composer require symfony/workflow:7.2
Example workflow configuration
The App\WorkflowState entity
Simple symfony command to execute the workflows transition
A simple event subscriber for debugging
When executing the command
bin/console ReproduceWorkflowBugCommand
Following output is shown
This output shows that the "workflow.reproduce_bug.entered.A" event was dispatched twice.
Once for transition "from_initial_place_to_a_and_b" which is expected and once for transition "from_b_to_d" which wasn't expected.
Possible Solution
The issue is caused within the
entered
method of theSymfony\Component\Workflow\Workflow
class as it dispatches the "workflow.[workflow name].entered.[place name]" events for the current marking places of the workflow.Code, wich causes the issue
vendor/symfony/workflow/Workflow.php
Fix
Instead of dispatching the events for each place of the marking, dispatch the events only for the "tos" of the transition. It was actually done this way until version 5.1 of the symfony workflow component.
Additional Context
No response
The text was updated successfully, but these errors were encountered: