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
- HttpClient: https://github.com/symfony/symfony/blob/aea15bc04f4a350c8caec9d6d4a9740249e114eb/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L2240-L2249
- https://github.com/symfony/symfony/blob/aea15bc04f4a350c8caec9d6d4a9740249e114eb/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L2152-L2156
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)
👍 for deprecating these services. With autowiring and named autowiring alias they are not needed IMHO
Oh, I think I misunderstood what you said.
If a workflow is named “foobar”, then only the
Symfony\....\WorkflowInterface $foobarshould be created, and not theSymfony\....\WorkflowInterface $foobarWorkflow, right ?In that case, I agree with you 👍🏼
The WTF behavior might even be worse, as the
HttpClientInterface $githubautowiring 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
githuband a HTTP client namedgithub, 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.aren’t you mixing the A and B cases here ? A already uses a prefix