-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Target Attribute must fail if the target does not exist #48555
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
Labels
Comments
I agree! and the failure message should suggest the correct name. |
We recently had the issue in one of our apps. We spelled the Target incorrectly and it was fine in test env but in production it failed because we add headers in the scoped client. Having an error would have helped a lot there ! 👍 |
"Help wanted" label added! |
chalasr
pushed a commit
to chalasr/symfony
that referenced
this issue
Dec 23, 2022
…l if the target does not exist (rodmen) This PR was merged into the 6.3 branch. Discussion ---------- [DependencyInjection] Target Attribute must fail if the target does not exist | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix symfony#48555 | License | MIT | Doc PR | - This change checks if an attribute is a Target to not auto bind with a new default object if the target name does not exists. The existent behavior should be in charge of suggest possible options for a typo on the Target name. I can't mark `allow edit by maintainers` I think because I'm open the PR from a organization repo. Commits ------- 983cd08 [DependencyInjection] Target Attribute must fail if the target does not exist
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Description
see: https://symfony.com/blog/new-in-symfony-5-3-service-autowiring-with-attributes#selecting-autowire-alias-with-attributes
If I create an http client:
And I want to inject it into my service, I can do:
But oups, I made a typo. I wrote
githubApi2
instead ofgithubApi
. But for Symfony it's OK. Instead it injects a new "blank" HttpClient (with no sane default configuration - no timeout for example).IMHO, if one want to inject a specific target, the target must be validated. And if the target does not exist, because another developer renamed it, you want an exception. for this.
see this comments for a previous discussion.
But IMHO, if the naming is not exactly the same as the autowire alias, it's fine to not raise an exception. But in this very use case, you really want this alias. Not another one.
So I would expect an exception.
WDYT?
Example
No response
The text was updated successfully, but these errors were encountered: