Description
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