Skip to content

[FrameworkBundle][HttpKernel] Let RequestPayloadValueResolver consider mapped argument type #57577

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
merged 1 commit into from
Aug 19, 2024

Conversation

unixslayer
Copy link
Contributor

@unixslayer unixslayer commented Jun 28, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #54617
License MIT

resolves #54617

In case of sending empty request, RequestPayloadValueResolver should consider argument type. In case empty request is considered invalid, having attribute as non-nullable without default value will cause to perform denormalization using empty input resulting with proper error message in response.

@carsonbot carsonbot added this to the 7.2 milestone Jun 28, 2024
@unixslayer unixslayer changed the title validate empty request MapQueryString/MapRequestPayload skips validation when empty request is sent [HttpKernel] validate empty request MapQueryString/MapRequestPayload skips validation when empty request is sent Jun 28, 2024
Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! minor comments

@yceruto
Copy link
Member

yceruto commented Jun 28, 2024

To help others understand the context of this PR, it would be great if you update the title as a new proposal, rather than focusing on it as an issue. Also, a good description is very appreciated, as it will help document the feature later on.

@carsonbot carsonbot changed the title [HttpKernel] validate empty request MapQueryString/MapRequestPayload skips validation when empty request is sent [FrameworkBundle] validate empty request MapQueryString/MapRequestPayload skips validation when empty request is sent Jun 28, 2024
@unixslayer unixslayer changed the title [FrameworkBundle] validate empty request MapQueryString/MapRequestPayload skips validation when empty request is sent [HttpKernel] let RequestPayloadValueResolver consider default value of an argument Jun 28, 2024
@carsonbot carsonbot changed the title [HttpKernel] let RequestPayloadValueResolver consider default value of an argument [FrameworkBundle][HttpKernel] let RequestPayloadValueResolver consider default value of an argument Jun 28, 2024
@unixslayer unixslayer requested a review from yceruto June 28, 2024 13:46
@yceruto
Copy link
Member

yceruto commented Jun 28, 2024

I think what you have achieved here is a better error message when an empty query string or an empty request payload is sent, and the targeted parameter is not nullable and doesn’t have a default value. In this case, the Serializer denormalizes the empty input as an empty object instead of just returning null, thus triggering the validation with a detailed error message.​

This is the critical code:

class Controller
{
    public function __invoke(#[MapQueryString] FooDto $foo) {}
}

Before -> Exception without message
After -> Exception with detailed message

@unixslayer unixslayer changed the title [FrameworkBundle][HttpKernel] let RequestPayloadValueResolver consider default value of an argument [FrameworkBundle][HttpKernel] let RequestPayloadValueResolver consider mapped argument type Jun 28, 2024
@unixslayer
Copy link
Contributor Author

@yceruto your last comment made me realize I may not achieved what I was hoping for. I have to clear out test cases and get back to you next week.

@unixslayer unixslayer marked this pull request as draft June 28, 2024 15:55
@unixslayer
Copy link
Contributor Author

Hi @yceruto, sorry for delay and possible confusion. I had to review test cases if they cover expected scenarios.

@unixslayer unixslayer marked this pull request as ready for review July 4, 2024 10:30
@unixslayer unixslayer requested a review from yceruto July 4, 2024 10:30
@unixslayer
Copy link
Contributor Author

@yceruto how do you guys deal with random test fails (8.4) or tests that fails only with one pipeline (8.2, low-deps)?

Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The symfony/framework-bundle package currently requires "symfony/http-kernel": "^6.4|^7.0", which causes issues when the FWB runs tests with an older symfony/http-kernel version (v6.4).

In these cases, we update the FWB composer.json file to require the newest symfony/http-kernel version instead, i.e. ^7.2, so the CI will use that version in the low-deps job.

However, I'm not sure it makes sense in this case where the only changes in FWB here are about tests. Actually, the FWB is still compatible with symfony/http-kernel: 6.4. Let's ask @symfony/mergers to be sure.

@unixslayer unixslayer force-pushed the 7.2 branch 3 times, most recently from 64f4449 to 8a6c852 Compare July 5, 2024 08:34
@unixslayer
Copy link
Contributor Author

@yceruto @GromNaN what about 8.4? Is that fail irrelevant for now?

@unixslayer unixslayer requested review from GromNaN and yceruto July 5, 2024 08:41
@OskarStark OskarStark changed the title [FrameworkBundle][HttpKernel] let RequestPayloadValueResolver consider mapped argument type [FrameworkBundle][HttpKernel] let RequestPayloadValueResolver consider mapped argument type Jul 5, 2024
@yceruto
Copy link
Member

yceruto commented Jul 5, 2024

@yceruto @GromNaN what about 8.4? Is that fail irrelevant for now?

They are unrelated, so you can ignore them.

@OskarStark OskarStark changed the title [FrameworkBundle][HttpKernel] let RequestPayloadValueResolver consider mapped argument type [FrameworkBundle][HttpKernel] Let RequestPayloadValueResolver consider mapped argument type Aug 16, 2024
@fabpot
Copy link
Member

fabpot commented Aug 19, 2024

Thank you @unixslayer.

@fabpot fabpot merged commit 5e76ca0 into symfony:7.2 Aug 19, 2024
8 of 10 checks passed
@fabpot fabpot mentioned this pull request Oct 27, 2024
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.

MapQueryString/MapRequestPayload skips validation when empty request is sent.
6 participants