Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] Handle previously converted DateTime arguments #46199

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

Merged

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Apr 28, 2022

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.

@chalasr
Copy link
Member

chalasr commented Apr 30, 2022

or turning off the param converters in full, which has other side effects),

Can you elaborate on the side effects? I'm really not fond of patching Symfony to support a mix of param converters and argument value resolvers

@mbabker mbabker force-pushed the datetime-param-converter-compat branch from 5fb1e88 to a48ecb6 Compare May 1, 2022 00:03
@mbabker
Copy link
Contributor Author

mbabker commented May 1, 2022

or turning off the param converters in full, which has other side effects),

Can you elaborate on the side effects? I'm really not fond of patching Symfony to support a mix of param converters and argument value resolvers

If your app already relies on them, then turning off the param converters (especially with #43854 not making it into 6.1) ends up being a much bigger refactoring. As much as I don't like the patch either, being a pragmatist here, I do think it solves the upgrade issue in a way that causes the least frustration for end-users (as otherwise you really either have to turn off the param converters and rewrite all controllers relying on those or mess with the container to remove one of the services to avoid the double-conversion issue), and this one condition can be re-evaluated or removed once we're at a version where both of the SensioFrameworkExtraBundle converters have replacements.

@chalasr
Copy link
Member

chalasr commented May 1, 2022

especially with #43854 not making it into 6.1

I thought it was in, thanks.

@nicolas-grekas
Copy link
Member

Thank you @mbabker.

@nicolas-grekas nicolas-grekas merged commit c70be09 into symfony:6.1 May 1, 2022
@mbabker mbabker deleted the datetime-param-converter-compat branch May 1, 2022 14:33
@fabpot fabpot mentioned this pull request May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug when convert datetime param on symfony 6.1
4 participants