-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Doctrine Bridge] fix priority for doctrine event listeners #22001
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
Conversation
949d0a6
to
e47cf38
Compare
e47cf38
to
9d9d4ef
Compare
It does what I expect and I dont see anything missing. Mentioning in the docs that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you @dmaicher. |
…s (dmaicher) This PR was merged into the 2.7 branch. Discussion ---------- [Doctrine Bridge] fix priority for doctrine event listeners | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21977 | License | MIT | Doc PR | - This fixes handling the priorities for doctrine event listeners. As found out by @chapterjason in #21977 the priority was incorrectly handled as soon as a listener had more than one tag (so listening to multiple events). With this changes all tagged listeners are globally sorted by priority (using the same stable sort approach as in the later available `PriorityTaggedServiceTrait`) and then added one by one to the event manager. I also updated the tests a bit as it was not covering all cases. We also have to extend the docs for it I think as it does not mention the `priority` and `lazy` option at all? http://symfony.com/doc/current/doctrine/event_listeners_subscribers.html Commits ------- 9d9d4ef [Doctrine Bridge] fix priority for doctrine event listeners
… suite (nicolas-grekas) This PR was merged into the 2.7 branch. Discussion ---------- [Bridge\Doctrine] Fix change breaking doctrine-bundle test suite | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Doctrine Bundle's test suite [is currently broken](https://travis-ci.org/doctrine/DoctrineBundle/jobs/215222182) with `2.8@dev` because the tests expect `addEventListener` to be called with an array as first arg, but #22001 optimized them away as string. Since internally strings are turned back into arrays, let's tweak that change and make Doctrine Bundle green again. Commits ------- 0577c7b [Bridge\Doctrine] Fix change breaking doctrine-bundle test suite
Just a heads up: This change can have bc breaking side effects in code that (probably unknowingly) relied on the order of unprioritized subscribers (and probably listeners). This happened to us. In addition to now recognizing priorities as expected this code also seems to change the order of unprioritized (or equally prioritized) subscribers (and probably listeners) compared to the old version. |
@eXaminator previously, the order of services with equal priority (if you don't define it, it is 0) was totally impossible to know. The sorting was not stable, so PHP was free to return the order it wants (which might depend on the PHP version). They are now in the order of service definitions (i.e. something which cannot change magically) |
@stof I understand that and I don't argue with it. But still, a PHP update could have changed and break things, this symfony update did change and break things (in our case). I just wanted to let everyone know that theses changes can have (and had) an impact on stuff besides just fixing a prior bug. |
@eXaminator PHP does not even guarantee that the sorting of ex-aequo is the same on all OS running it (and maybe not on the same machine for 2 subsequent runs, even though this one is unlikely). |
@eXaminator thanks for the info and sorry that it caused problems for you 😢 But as @stof said this is the only way we can actually guarantee a correct & stable sorting by priorities now. It was clear that with this patch the behavior will change compared to the previous version in certain scenarios that relied on the magic & unstable sorting from before. |
Like I said, I'm not trying to argue against this patch. It makes sense and our code is at fault for breaking (or in this case also the DoctrineExtensionBundle to some degree, as Softdeleteable and Tree don't work together very well and our workaround for that stopped working now). But it was a pain to debug and I just wanted to let you guys know that it has potential bc breaking side effects on code that relies on the old (wrong) behavior (like having one subscriber clean up the unit of work before the next subscriber gets to it, as was the case here). |
…s (dmaicher) This PR was merged into the 3.4 branch. Discussion ---------- [Doctrine Bridge] fix priority for doctrine event listeners | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21977 | License | MIT | Doc PR | - As discussed in #27126 this ports changes from #22001 to 3.4 that were dropped when merging 2.8 into 3.2 here: dc66960#diff-27d2e9b071d766df504c3fe4131e7abf I took my original changeset from 2.8 and applied all commits since then on top of that. Commits ------- b3ac938 [Doctrine Bridge] fix priority for doctrine event listeners
This fixes handling the priorities for doctrine event listeners. As found out by @chapterjason in #21977 the priority was incorrectly handled as soon as a listener had more than one tag (so listening to multiple events).
With this changes all tagged listeners are globally sorted by priority (using the same stable sort approach as in the later available
PriorityTaggedServiceTrait
) and then added one by one to the event manager.I also updated the tests a bit as it was not covering all cases.
We also have to extend the docs for it I think as it does not mention the
priority
andlazy
option at all? http://symfony.com/doc/current/doctrine/event_listeners_subscribers.html