Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Validation cache duplicates constraints #23544

Copy link
Copy link
Closed
@ossinkine

Description

@ossinkine
Issue body actions
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

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