-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Empty tags get lost in instanceof conditionals #48388
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
…re tag when it's already set with attributes" (nicolas-grekas) This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Revert "bug #48027 Don't autoconfigure tag when it's already set with attributes" | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | | Tickets | Fix #48388 | License | MIT | Doc PR | - Reverting #48027, which is a regression. Commits ------- bd2780a Revert "bug #48027 [DependencyInjection] Don't autoconfigure tag when it's already set with attributes (nicolas-grekas)"
Me and @Seldaek are wondering about the use case for having two tags. Could anyone share their's? |
@nicolas-grekas this can happen through auto configuration - and also when you need to add autowiring hints for service subscribers. Example: services:
_defaults:
autoconfigure: true
App\Test:
tags:
- { name: container.service_subscriber, id: App\Foobar } namespace App;
use App\Foobar;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
class Test implements ServiceSubscriberInterface
{
public static function getSubscribedServices(): array
{
return [Foobar::class => Foobar::class];
}
}
i.e.: when autoconfiguration is enabled, Symfony will automatically add an (empty!) |
In my case it's basically a BC layer. Even though the Symfony app itself uses the FQCNs, there are still samo old services (written in languages such as GO) that use the old naming convention & communicate with the Symfony app through a message queue. The idea is to standardize this over time. |
@fritzmg your use case makes sense, and that kinda matches the issue I had in #48019 - except in that case the double tag actually caused problems for me. I can totally see that you do want the most specific tags to be added, i.e. in this example you want So IMO @nicolas-grekas's fix would be fine as long as it ensures the most meaningful tag is kept. i.e. do not auto-configure an empty tag (from an interface or even an attribute?) if there is already a tag present which has meaningful data, but if there is already an autoconfigured tag present with no data then it should be overwritten. |
But that solely depends on the service tag, does it not? I did not do a deeper dive whether the non-specific |
Yeah if you have multiple with different properties that's fine and the use case makes sense. I just don't see a use case where autoconfiguring a second empty tag makes sense. Especially with the interface it's quite surprising as it's implicit and might even be a BC break situation if you upgrade and a class becomes autoconfigured suddenly due to a new feature. |
The simple symfony/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php Lines 42 to 46 in 205cb5a
|
Ok I see. Then I guess it's probably not fixable as too much depend on this behavior, no matter how sound it was to begin with. |
We could deprecate the empty service_subscriber tag and instruct developers to use something like |
Same applies to |
Symfony version(s) affected
v5.4.16
Description
Symfony v5.1.16 has introduced a BC break in how autoconfiguring works. The issue was caused by #48027 .
How to reproduce
Before #48027 the
app.foo_locator
service locator would have 2 aliases for theFoo
service (which is the behavior I need):After upgrading to v5.4.16, this is no longer the case:
Since the
Foo
service has an#[AutoconfigureTag]
attribute, theFooInterface
is skipped during autoconfiguration.Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: