-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Constructor arguments are mapped wrong if request is missing an argument #52422
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
This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] Fix denormalize constructor arguments | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #52499, Fix #52422 | License | MIT Since this PR: #51907, objects with partial constructor parameters were wrongly instantiated. This PR fixes that issue by delegating the properties values assignment, by unsetting normalized data only when the constructor has been called properly. This might correct #50759 as well. Commits ------- 8f7c7ae [Serializer] Fix denormalize constructor arguments
Unfortunately, this is not fixed in the latest 6.4 version for me. Same Request and Project as before. Not 100% sure if this is a Sending a request against {
"password": "abc",
"old_password": "def"
} Results in:
Check Btw. maybe the nullable {
"password": "abc",
"old_password": "def"
} Results in:
With all validations triggered (not only for the missing email). |
Symfony version(s) affected
6.3.6
Description
This issue rose while using the
MapRequestPayload
Attribute on a request.Consider the following DTO and Controller:
When calling this route with
the created object looks like this:
the values are not correctly mapped
How to reproduce
A simple way to reproduce it is described above.
It's also possible to use my github project: https://github.com/Havrin/symfony-payload-bug
start it and throw the following request against
https://localhost/api/change-password
Possible Solution
While debugging I noticed, that https://github.com/symfony/serializer/blob/1197823bacefc3397fafb8f10709c1574b2f69ce/Normalizer/AbstractNormalizer.php#L376 is creating an array of values with just an index-number as key.
After creating the object in https://github.com/symfony/serializer/blob/1197823bacefc3397fafb8f10709c1574b2f69ce/Normalizer/AbstractNormalizer.php#L420 the values are wrongly mapped. Seems like the code is not correctly using the name as key but rather the index-number.
Additional Context
The wrong mapping started occurring after this fix: #51907
The text was updated successfully, but these errors were encountered: