Skip to content

[Validator] GroupSequence won't work on inherited classes #47092

Closed
@mvhirsch

Description

@mvhirsch

Symfony version(s) affected

6.1.2

Description

Using Symfony\Component\Validator\Constraints\GroupSequence on a class works, but it won't work on child classes or Doctrine\Proxy classes.

I've just tested with latest Symfony version, probably some more are affected.

It looks like the same issue like in #20251, but GroupSequenceProvider (and implementing GroupSequenceProviderInterface) works fine. Instead I just use GroupSequence on my entity class.

How to reproduce

Using a Doctrine entity like this:

#[GroupSequence(['MyEntity', 'Strict'])
#[Entity(repositoryClass: MyEntityRepository::class)]
class MyEntity
{
    #[NotBlank(groups: ['Strict'])
    private string $property = '';
}

While validating the Entity, I expect at least one error (NotBlank on $property):

final class MyService
{
    public function __construct(private readonly MyEntityRepository $repository, private readonly ValidatorInterface $validator) {}

    public function doSomething()
    {
        // now a Doctrine proxy class, inheriting MyEntity */
        $entity = $this->repository->findBy(/* something */);

        // 'Default' isn't necessary, but emphasize my test case
        $errors = $this->validator->validate($entity, null, ['Default']); 

        count($errors); // 0
    }
}

Possible Solution

I think the problem lays in LazyLoadingMetadataFactory. It checks if my class MyEntity implements GroupSequenceProviderInterface (which does not). So therefore it should also check if the class (or it's parents) has GroupSequence on it's class level defined.

Additional Context

No response

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