symfony: [Validator] Constraint validator "Symfony\Component\Validator\Constraints\RequiredValidator" does not exist or is not enabled

Symfony version(s) affected: 3.4.40

3.4.39 is OK

Description
I get an error: Constraint validator “Symfony\Component\Validator\Constraints\RequiredValidator” does not exist or is not enabled. Check the “validatedBy” method in your constraint class “Symfony\Component\Validator\Constraints\Required”. Line: 49 File: “/data/www/site/current/vendor/symfony/symfony/src/Symfony/Component/Validator/ContainerConstraintValidatorFactory.php”

How to reproduce

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Required;
use Symfony\Component\Validator\Validator\ValidatorInterface;

//$this->validator - ValidatorInterface (service @validator)
$violations = $this->validator->validate($value, new All([
            new Collection([
                'email' => [
                    new NotBlank(),
                    new Email(),
                ],
                'verified' => [
                    new Required(),
                    new Choice(['strict' => true, 'choices' => [1, 0, "1", "0", true, false]]),
                ],
            ]),
        ]));

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

@R11baka Thank you, I was able to reproduce. The behaviour changes is related to #36365. I don’t know how we could achieve both (the solved issue and the way the constraint is used in the example). However, using the Required constraint in the way as in the reproducer doesn’t make much sense. So I am not sure if we really need to change anything.