-
Notifications
You must be signed in to change notification settings - Fork 49
Add default_client
configuration option
#479
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
base: 2.x
Are you sure you want to change the base?
Conversation
Added `default_client` configuration option to disable assigning the first client as default client and to remove the default client service.
/cc @dbu whenever you have time 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
picking the first service as default if no default is specified explicitly seems to be common practice in symfony, e.g. doctrine orm does it as well.
it is convenient when you have only one connection. but with multiple, i see the problem that implicit default is very non-obvious.
i would suggest we do not add a new configuration option - default_client_autowiring already allows to prevent autowiring.
instead, we should trigger a deprecation when more than 1 client is defined and default_client_autowiring is set to true and main_alias.client is not explicitly set, to ask people to explicitly chose which client they want to autowire when the service does not specify which client it wants.
In our project, we don't want to have a default, because we want developers to set specific clients per use case. So that every use case can be configured on their own without impacting other use cases. How to deal with that? |
It could still be done when there is only 1 client defined, mark that as default. If you add more, stop doing it. |
if (!$config['default_client']) { | ||
$container->removeAlias('httplug.client'); | ||
$container->removeAlias('httplug.client.default'); | ||
$container->removeDefinition('httplug.client.default'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we should remove this definition. it has no semantic meaning for symfony, and if i define a client that i call default
it would be very unexpected to just nuke my definition.
however, we should additionally remove the httplug.psr18_client.default alias (from the main_classes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good catch indeed. It's naive for me to just remove this, because I assume it's the default one created by the bundle.
What if we create a new major version, where we do the following:
|
the to avoid BC breaks, i suggest we add if i want to keep the default to do autowiring. this seems more in line with what symfony does, e.g. the symfony http client. |
What's in this PR?
Added
default_client
configuration option to disable assigning the first client as default client and to remove the default client service.Why?
Today we had an outage because we removed our the
default
client from our list of clients (multiple).Some service was stil referencing
httplug.client.default
but this was not producing an error on CI.It turns out this is a feature, which should be called a foot gun in my opinion:
HttplugBundle/src/DependencyInjection/HttplugExtension.php
Lines 144 to 153 in 51173c3
The logic of this is flawed. If one changes the order of the
clients
list, suddenly another client will become the default.In my opinion we should completely remove this default auto selection mode, but that might be a breaking change no one wants to do right now.
So in this PR, I propose we add a configuration option to disable this logic.
Checklist