-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
#[CurrentUser] : Unable to guess how to get a Doctrine instance from the request information for parameter "user". #40333
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
Comments
Confirmed: The |
My user is a Doctrine entity and I enabled param converters. |
As a quick fix, we could make To fix this once for all, we would need to either make argument value resolvers run before param converters (I've no idea how much use cases this could break), or to fully replace param converters by argument value resolvers. |
this is the way to go. That was the plan that has never been completed. |
As a work around it's possible to type hint the argument as Optionally add an |
@danfraticiu In that case, you don't need the attribute. Injecting the user into a controller action as always worked by declaring |
Hey, thanks for your report! |
Hi, |
Are we anywhere closer to having this resolved? Using the functionality will improve code immensely. Thank you. |
This will probably be a won't fix. The solution that is being worked on is abandoning FrameworkExtraBundle, see #44705. |
Happy to see them moved to the core. With no ETA, I'll do the workaround of:
which keeps the static analysers happy. Thanks for responding! |
…nts (mbabker) This PR was merged into the 6.1 branch. Discussion ---------- [HttpKernel] Handle previously converted `DateTime` arguments | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix sensiolabs/SensioFrameworkExtraBundle#770 | License | MIT | Doc PR | N/A I'm not sure I like this fix, but given the order of operations between the param converters in SensioFrameworkExtraBundle and the controller argument resolvers in the HttpKernel component, this is probably going to cause the least number of headaches for users when upgrading. And in some ways, this is the same problem as #40333 but in reverse. Because the param converters are triggered on the `kernel.controller` event, they will handle converting values before the controller argument resolvers are fired. This means that a typehinted `DateTimeInterface` will potentially be handled twice (once by the param converter, once by the argument resolver). To avoid the `TypeError` noted in the issue, a practical fix is to gracefully handle a previously converted value in this resolver. As the other options aren't great (removing services from the container or turning off the param converters in full, which has other side effects), this is probably the most practical fix. Commits ------- a48ecb6 Handle previously converted DateTime arguments
…usse, nicolas-grekas) This PR was merged into the 6.2 branch. Discussion ---------- [DoctrineBridge] Add an Entity Argument Resolver | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | part of #40333 | License | MIT | Doc PR | todo This PR provides an Argument Resolver for Doctrine entities. This would replace the SensioFramework's DoctrineParamConverter (in fact most of the code is copy/pasted from here) and helps users to disable the paramConverter and fix the related issue. usage: ```yaml sensio_framework_extra: request: converters: false services: Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver: ~ ``` ```php #[Route('/blog/{slug}')] public function show(Post $post) { } ``` or with custom options ```php #[Route('/blog/{id}')] public function show( #[MapEntity(entityManager: 'foo', expr: 'repository.findNotDeletedById(id)')] Post $post ) { } ``` Commits ------- 5a3df5e Improve EntityValueResolver (#3) 4524083 Add an Entity Argument Resolver
Can we close here now that #44705 is finished? |
Yes, that's not something we can tackle as a bug on stable versions. As of 6.2, one will be able to drop FrameworkExtraBundle and the issue will go away. |
This reverts commit d92865d. This is necessary per symfony/symfony#40333, since LocalAccount is both a Doctrine entity and the CurrentUser class, which is a won'tfix for the FrameworkExtraBundle. With Symfony 6.2, this will be fixed by the EntityArgumentResolver (symfony/symfony#43854). Until then, let's stick to what we have.
Symfony version(s) affected: 5.2.3
sensio/framework-extra-bundle: 6.1.1
Description
Hi,
I have an error when use #[CurrentUser]:
Unable to guess how to get a Doctrine instance from the request information for parameter "user".
How to reproduce
The text was updated successfully, but these errors were encountered: