Skip to content

[Validator] GroupSequenceProvider "provider" parameter gets ignored and results in error #57677

@mazumba

Description

@mazumba

Symfony version(s) affected

7.0.x

Description

According to the docs, it should be possible to set service implementing the GroupProviderInterface interface through the GroupSequenceProvider attribute via its provider argument. This way, the validated class does not require to implement the GroupSequenceProviderInterface.
Docs (current): https://symfony.com/doc/current/validation/sequence_provider.html#advanced-validation-group-provider
Docs (6.4): https://symfony.com/doc/6.4/validation/sequence_provider.html#advanced-validation-group-provider

This functionality currently gets ignored and results in an error

Uncaught PHP Exception Symfony\Component\Validator\Exception\GroupDefinitionException: "Class "App\Model\Payload" must implement GroupSequenceProviderInterface." at ClassMetadata.php line 441

This works in 6.4 but not anymore in 7.0 and up
Tested in Symfony 7.1.2

How to reproduce

Example that should work but doesn't:

#[Assert\GroupSequenceProvider(provider: PayloadGroupProvider::class)]
final class Payload
{
    ...
}

final readonly class PayloadGroupProvider implements GroupProviderInterface
{
    public function getGroups(object $object): array|GroupSequence
    {
        return ['Payload', 'SomeOtherGroup'];
    }
}

Possible Solution

In the AttributeLoader when checking for the GroupSequenceProvider attribute, also check for the provider argument and set the content inside the ClassMetadata object.

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