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
[DoctrineBridge] Cannot remove Lazy-loaded listeners by object #51057
Comments
Indeed this seems like a bug to me 😕 I think it makes sense to re-index the listener with the Regarding the other issue mentioned: We might have to initialize listeners then for the event(s) so we can properly remove also the lazy instances? Not sure how common it is to remove listeners and how bad the performance penalty would be 🤷♂️ Or we can first try to remove it and only if we cannot find the listener then initialize all of them and try again? |
When I made some try, it also require to keep a map "oldHash" => "newHash", to avoid issue if someone does:
Does something like this seems ok to you @dmaicher ? 5.4...VincentLanglet:symfony:removeListeners |
@VincentLanglet yeah looks good. I will take another look once you opened a PR, ok? |
…ners by object (VincentLanglet) This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [DoctrineBridge] Bugfix - Allow to remove LazyLoaded listeners by object | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #51057 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> cc `@dmaicher` Commits ------- 8965c0c [DoctrineBridge] Bugfix - Allow to remove LazyLoaded listeners by object
Symfony version(s) affected
6.3.x, but maybe lower
Description
Let's say I the following code
To me this is suppose to remove all the existing event listener.
Seems like with the
ContainerAwareEventManager
it does nothing.If I dump the
listeners
, I get:Which means that, when I call
removeEventListener($event, $listener)
, I pass the event and the object but in the remove method, the hash computed is the spl_object_hash and not the one with_service
prefix.symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php
Lines 128 to 146 in bd04cda
I would say something is wrong with the
initializeListeners
methodsymfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php
Lines 166 to 176 in bd04cda
because it transform the
$listener
as string to the object instance, but without changing the hash.the $lister property is modified from
to
when it should be
Possible Solution
First I thought of something like
Maybe the method should be
But it require listeners to be initialized then.
Which means that:
won't do nothing when
will remove the lazy (now loaded) listener. Which would be weird.
Reproducer
This is a reproducer in the Symfony Tests:
Additional context
This seems cause by the PR #31335 and reported here #31335 (comment)
@Koc @nicolas-grekas @dmaicher
The text was updated successfully, but these errors were encountered: