Problem/Motivation
I discovered an interesting bug, thanks to a failing Commerce invoice test, caused by #3083407: Fire intended events when invoking a specific transition.
I realized that because we're storing the transition to apply in a variable and because we're not "nullifying" the transition after applying it/dispatching the event, changing the entity state (without calling the applyTransition() or applyTransitionById() during the same request would result in the wrong transition events to be fired (for the previously applied transition).
So basically with the following code:
$entity->getState()->applyTransitionById('create');
$entity->save();
$entity->set('state', 'canceled')->save();
The second save would trigger the events associated to the first transition applied (instead of the events associated to the "cancel" transition.
I managed to write a failing test.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3227087-3.patch | 3.71 KB | jsacksick |
| #3 | 3227087-3-tests-only.patch | 3.11 KB | jsacksick |
Comments
Comment #2
jsacksick commentedComment #3
jsacksick commentedI believe this fix deserves tagging a new State machine release.
Comment #4
jsacksick commentedNote that I previously tried to nullify the
transitionToApply()variable right after we're accessing it, but this was causing the events triggered on postSave() to be incorrect. So this needs to happen onpostSave().Comment #5
jsacksick commentedComment #7
jsacksick commentedCommitted!