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

[2.2] [Validator] Constraints\Valid does not respect "groups" option #3622

Copy link
Copy link
Closed
@ruimarinho

Description

@ruimarinho
Issue body actions

I have an entity where I'm using the following validators:

/**
 * @Assert\Callback(methods={"isValid"}, groups={"group1", "group2"})
 */
class UserProduct
{
    /**
     * @var string $title
     * @Assert\NotBlank(message="title.blank", groups={"group1", "group2"});
     */
    private $title;

    /**
     * @var Project\AuthenticationBundle\Entity\User
     * @Assert\Valid(groups={"group2"});
     */
    private $user;

Calling $this->get('validator')->validate($userProduct, array('group1')) asserts the class constraint (@Assert\Callback) and the $title property but also the $user one too, even though it's not included in the validation group. The same happens if no groups are passed to the Valid constraint.

Removing the @Assert\Valid() constraint and running the same validation again for group1 does not assert the $user property, as expected.

The MemberMetadata class appears to always force the cascading of the Valid constraint, although I'm unsure if this is exactly related to the issue I'm experiencing.

// Symfony\Component\Validator\Mapping\MemberMetadata.php
        if ($constraint instanceof Valid) {
            $this->cascaded = true;
            $this->collectionCascaded = $constraint->traverse;
        } else {
            parent::addConstraint($constraint);
        }

Running on Symfony2 master.

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.