Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings

[Serializer] Handling of MapQueryString fails with Serializer 8.1.5 due to too early validation #65623

Copy link
Copy link

Description

@heiglandreas
Issue body actions

Symfony version(s) affected

8.1.5

Description

After updating symfony/serializer we encountered issues when using #[MapQueryString] with an object containing a parameter-annotation list` and a validator chain.

How to reproduce

#[Route('test',methods: 'GET', format: 'json')]
class MyController
{
  public function __invoke(
	#[MapQueryString()]
    QueryString $queryString = new QueryString()
  ) {}
}

class QueryString
{
  /**
   * @param list<positive-int> $ids
   */
  public function __construct(
  	#[Assert\All(constraints: [
      new Assert\NotBlank(message: 'Invalid id: value must not be empty'),
      new Assert\Regex('|^[1-9][0-9]*$|', message: 'Invalid id: value must be a positive integer'),
    ])]
    public ?array $ids = null,
  ) {}
}

When calling /test?ids[]= or /test?ids[]=foo with symfony/serializer:8.1.4 we got the error message Invalid id: value must not be empty resp. Invalid id: value must be a positive integer, With symfony/serializer:8.1.5 we get This value should be of type int.

The validator-chain is never triggered.

Possible Solution

  • Replacing the list<positive-int> with list<mixed> solves the issue - with the drawback of being the wrong type.
  • Staying on symfony/validator:8.1.4 will not be feasible

Additional Context

This seems to have been introduced in symfony/serializer@c1c0a96 - commited by @nicolas-grekas and co-authored by @SamuilovAD

Reactions are currently unavailable

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

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.