Skip to content

[Validator] Change in behavior of Unique constraint in Symfony 7.2.0 #59037

Closed
@Wojdylak

Description

@Wojdylak

Symfony version(s) affected

7.2.0

Description

In #57436 a change was introduced that affects the behavior of the Unique constraint. Specifically, a line was added in UniqueValidator:

->atPath("[$index]" . (null !== $constraint->errorPath ? ".{$constraint->errorPath}" : ''))

This change now adds [$index] to every propertyPath, even when errorPath isn't set. This alters the previous behavior and might cause issues, especially in existing implementations where the index wasn't part of the path.

It would be great if this change could be made optional or if the old behavior could be kept to avoid breaking compatibility with older code.

How to reproduce

Compare the propertyPath for an array field with a Unique constraint in Symfony 7.1 (which should be just the property name, e.g., propertyName) and Symfony 7.2.0 (where it includes the index, e.g., propertyName[$index]).

Possible Solution

No response

Additional Context

No response

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