symfony: [FrameworkBundle] Conflict between generated services ID

Symfony version(s) affected: all

Description

Symfony used to namespace all generated ID but it’s not the case for some services

And maybe more

How to reproduce

framework:
    http_client:
        scoped_clients:
            github:
                base_uri: http://github.com
    cache:
        pools:
            github: null

With the previous configuration, http_client replaces the cache definition (because http client configuration is processed after cache configuration).

>…goire/dev/labs/symfony/symfony-5.4(master *) bin/console  debug:container github

 // This service is a private alias for the service .debug.github                                                       

Information for Service ".debug.github"
=======================================

 ---------------- -------------------------------------------------- 
  Option           Value                                             
 ---------------- -------------------------------------------------- 
  Service ID       .debug.github                                     
  Class            Symfony\Component\HttpClient\TraceableHttpClient  

And If I change the name of the github http client:

>…goire/dev/labs/symfony/symfony-5.4(master *) bin/console  debug:container github

Information for Service "github"
================================

 An adapter that collects data about all cache calls.

 ---------------- -------------------------------------------------- 
  Option           Value                                             
 ---------------- -------------------------------------------------- 
  Service ID       github                                            
  Class            Symfony\Component\Cache\Adapter\TraceableAdapter  

Possible Solution

We must namespace all services ID based on semantic configuration like we did in the past with messenger, workflow, etc

Additional context

This issue is a bit annoying with a different use case:

Once I declared a github client, I’m no longer able to use bin/console debug:container github to find all services that match github because a github service exists. Yes, I can still use | grep github, but still 😃

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (18 by maintainers)

Most upvoted comments

👍 for deprecating these services. With autowiring and named autowiring alias they are not needed IMHO

Because it reduces the DX by forcing ppl to learn about that prefix/suffix, and also because it forces ppl to use a specific name on their classes, eg $foobarStateMachine

Oh, I think I misunderstood what you said.

If a workflow is named “foobar”, then only the Symfony\....\WorkflowInterface $foobar should be created, and not the Symfony\....\WorkflowInterface $foobarWorkflow, right ?

In that case, I agree with you 👍🏼

The WTF behavior might even be worse, as the HttpClientInterface $github autowiring alias would still exist, but referencing a cache pool…

the tricky things about not having a prefix in service ids is that the names you give to your HTTP clients, your cache pools and your messenger transport must now avoid conflicts with all service ids of the container. If you have a cache pool named github and a HTTP client named github, one of them will be overwritten by the other (depending on the order in which FrameworkBundle configures them). This can lead to lots of WTF if you face this, especially when all older components were configured with service id prefixes to avoid issues.

* update default service id for A (ie: set a prefix).

aren’t you mixing the A and B cases here ? A already uses a prefix