Skip to content

TraceableVoter seems to retain tags from inner service #29550

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

Closed
kbond opened this issue Dec 10, 2018 · 2 comments
Closed

TraceableVoter seems to retain tags from inner service #29550

kbond opened this issue Dec 10, 2018 · 2 comments

Comments

@kbond
Copy link
Member

kbond commented Dec 10, 2018

Symfony version(s) affected: 4.2.0

Description
I have a voter that implements ServiceSubscriberInterface. When clearing the cache I get the following error:

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]                                                                                         
  Service "debug.security.voter.App\Voter\MyVoter" must implement interface "Symfony\Contracts\Service\ServiceSubscriberInterface".

How to reproduce
Create a auto-configured voter that implements ServiceSubscriberInterface and clear the cache in dev.

Possible Solution
Not a solution but if I remove this bit of code from AddSecurityVoter, it works as expected.

Additional context
Possibly related to #29385?

Looks to have been introduced in #27914.

@chalasr
Copy link
Member

chalasr commented Dec 11, 2018

Confirmed.
The fact that RegisterServiceSubscribersPass runs after DecoratorServicePass makes it impossible to decorate a service implementing ServiceSubscriberInterface if the decorator does not implement it.
I think the following change could fix it:

diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php
index 31104fb..d547c3e 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php
@@ -51,12 +51,12 @@ class PassConfig
         $this->optimizationPasses = array(array(
             new ResolveChildDefinitionsPass(),
             new ServiceLocatorTagPass(),
+            new RegisterServiceSubscribersPass(),
             new DecoratorServicePass(),
             new ResolveParameterPlaceHoldersPass(false),
             new ResolveFactoryClassPass(),
             new FactoryReturnTypePass($resolveClassPass),
             new CheckDefinitionValidityPass(),
-            new RegisterServiceSubscribersPass(),
             new ResolveNamedArgumentsPass(),
             new AutowireRequiredMethodsPass(),
             new ResolveBindingsPass(),

Could you please try it and confirm everything keeps working?
Thanks

@kbond
Copy link
Member Author

kbond commented Dec 12, 2018

Thanks @chalasr - your fixed worked. I opened a PR

nicolas-grekas added a commit that referenced this issue Dec 12, 2018
…ervicePass (kbond)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] move RegisterServiceSubscribersPass before DecoratorServicePass

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #29550
| License       | MIT
| Doc PR        | n/a

From #29550 (comment): The fact that `RegisterServiceSubscribersPass` runs after `DecoratorServicePass` makes it impossible to decorate a service implementing `ServiceSubscriberInterface` if the decorator does not implement it.

Commits
-------

c3271d9 [DI] move RegisterServiceSubscribersPass before DecoratorServicePass
@chalasr chalasr closed this as completed Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants