Skip to content

Validation cache duplicates constraints #23544

Closed
@ossinkine

Description

@ossinkine
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version >=3.2.2 >=3.3.0-beta1

Validation caching merges constraints for class and all of its parents. It's wrong behaviour, because the class already contains constraints from parent classes. As a result we have duplicated constraint.

The way to reproduce

Create two models, the second one extends the first one:

namespace AppBundle\Model;

class Foo
{
    public $foo;
}
namespace AppBundle\Model;

class Bar extends Foo
{
}

Create validation config, add constraint to the first class, the second class should be defined (empty or with some constraints)

AppBundle\Model\Foo:
    constraints:
        - Expression: "this.foo !== null"

AppBundle\Model\Bar:

And validation of new Bar object will generates two duplicated violations:

$container->get('validator')->validate(new Bar()));

Note: this code should be executed in prod environment, because test environment doesn't use validation cache by default.

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