Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] incorrect list of tags with the tagged service when using aliases #51258

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
Setest opened this issue Aug 3, 2023 · 4 comments

Comments

@Setest
Copy link

Setest commented Aug 3, 2023

Symfony version(s) affected

6.0

Description

If we use an abstract service and extend a class from it with an alias in the name and specifying the class attribute, and write the tags attribute in the descendant, then when building the cache after calling the findTaggedServiceIds method, it returns duplicated tags: one for the alias and one for the full class path.

How to reproduce

services.yaml

app.processor:
    class: App\Processor\AbstractProcessor
    abstract: true
    calls:
        - setLogger: [ '@logger' ]
        - setSerializer: [ '@jms_serializer' ]

app.processor.base:
    class: App\Processor\BaseProcessor
    parent: app.processor
    tags:
        - {name: 'enqueue.topic_subsciber', client: 'base' }

I used vendor/enqueue/enqueue/Symfony/Client/DependencyInjection/BuildTopicSubscriberRoutesPass.php (file of enqueue/enqueue package) for reproducing it, but it does not big matter, it just my case.

$tag = 'enqueue.topic_subscriber';
$routeCollection = new RouteCollection([]);
$tags = $container->findTaggedServiceIds($tag);

dd($tags);

In result i have:

^ array:2 [
  "App\Processor\BaseProcessor" => array:1 [
    0 => array:1 [
      "client" => "base"
    ]
  ]
  "app.processor.base" => array:1 [
    0 => array:1 [
      "client" => "base"
    ]
  ]
]

Which creates an incorrect amount of $routeCollection, because there is no information in the result data that it is the same class.

But if we did not use aliases:

services.yaml

app.processor:
    class: App\Processor\AbstractProcessor
    abstract: true
    calls:
        - setLogger: [ '@logger' ]
        - setSerializer: [ '@jms_serializer' ]

App\Processor\BaseProcessor:
    parent: app.processor
    tags:
        - {name: 'enqueue.topic_subsciber', client: 'base' }

Then count of tagged classes will be correct:

^ array:1 [
  "App\Processor\BaseProcessor" => array:1 [
    0 => array:1 [
      "client" => "base"
    ]
  ]
]

May be its not fault of abstract class. But i did not checked it fully.

Possible Solution

Some how exclude duplicates and leave only tagged aliases.

Additional Context

No response

@xabbuh
Copy link
Member

xabbuh commented Aug 4, 2023

if I understand the issue correctly, this is similar to #48019 which was tried to be fixed in #48027 but was later reverted (see #48482) as it led to other issues (see #48388)

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

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

3 participants