Skip to content

[Form][Validation] Unique entity validator throw undefined index if no data is provided #23486

Closed
@flohw

Description

@flohw
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version >=2.7.25

The UniqueEntityValidator throw an "undefined index error" when submitting no data or null value on a defined entity's field.

My entity has UniqueEntity(fields={"reference", "supplier"}) constraint.
In my functional test I submit an empty array as post data.
The response is "Undefined index: reference".

After some research, the bug was introduced here symfony/doctrine-bridge@40941a3#diff-e59b775599f36ee1318299634bc1be79 when line 88 has been splitted.
In my exemple $criteria['reference'] does not exist any more and the error (undefined index) occurs on line 137
If $criteria[$fieldName] = $fieldValue; were between line 88 and 90 it would works properly.

Sorry but I am not sure about the solution and don't know how to create a test for this case. If someone can help me about that.

Thank you.

Curiosity question : is there a reason to use ClassMetdata attributes (like reflFields) to get field values instead of getFieldValue($entity, $field) method?

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