Skip to content

[Serializer] Constructor arguments are mapped wrong if request is missing an argument (re-open) #53076

@Havrin

Description

@Havrin

Symfony version(s) affected

6.4

Description

Unfortunately, the fix from #52422 did not help in the latest 6.4 version for me. Same Request and Project as before. Not 100% sure if this is a Serializer or MapRequestPayload Problem.

How to reproduce

Project updated to 6.4: https://github.com/Havrin/symfony-payload-bug

Sending a request against http://localhost/api/change-password with

{
  "password": "abc",
  "old_password": "def"
}

Results in:

object(App\DTO\ChangePassword)#192 (3) {
    [
        "oldPassword":"App\DTO\ChangePassword":private
    ]=>
  NULL
  [
        "email":"App\DTO\ChangePassword":private
    ]=>
  string(3) "abc"
  [
        "password":"App\DTO\ChangePassword":private
    ]=>
  string(3) "def"
}

Check var_dump in https://github.com/Havrin/symfony-payload-bug/blob/master/src/EventSubscriber/ExceptionResponseEventSubscriber.php

Btw. maybe the nullable oldPassword is a problem. Using a not nullable oldPassword can be tested by using the same payload against http://localhost/api/change-password-without-null

{
  "password": "abc",
  "old_password": "def"
}

Results in:

object(App\DTO\ChangePasswordWithoutNull)#192 (0) {
    [
        "email":"App\DTO\ChangePasswordWithoutNull":private
    ]=>
  uninitialized(string)
  [
        "password":"App\DTO\ChangePasswordWithoutNull":private
    ]=>
  uninitialized(string)
  [
        "oldPassword":"App\DTO\ChangePasswordWithoutNull":private
    ]=>
  uninitialized(string)
}

With all validations triggered (not only for the missing email). This is mentioned in #53075

Possible Solution

No response

Additional Context

Apologize if re creating a new ticket was not the right move. Feel free to close this and re open the other one.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions