Skip to content

[Validator] AutoMapping Constrainst #34672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mpiot opened this issue Nov 28, 2019 · 1 comment
Closed

[Validator] AutoMapping Constrainst #34672

mpiot opened this issue Nov 28, 2019 · 1 comment

Comments

@mpiot
Copy link
Contributor

mpiot commented Nov 28, 2019

Symfony version(s) affected: 4.4.0

Description
When add the annotation @Assert\DisableAutoMapping(), the Validator component try to find the DisableAutoMappingValidator class, but it doesn't exists. Then you have a 500 error.

How to reproduce
In validator.yaml, under farmework -> validation, add:

#auto_mapping:
#    App\Entity\: []

Then, in an entity add the special @Assert\DisableAutoMapping(). On the next validation, the Validator try to find the DisableAutoMappingValidator and fail.

Possible Solution
At the moment in my case, I've just create the Validator with a return in the validate method. Because, the Assert is not use as a Validator by the Validator component. But, this is apparently the Bridge/Doctrine/Validator/DoctrineLoader that take care of this annotations.

<?php

namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

class DisableAutoMappingValidator extends ConstraintValidator
{
    public function validate($value, Constraint $constraint)
    {
        return;
    }
}

But there is maybe a better solution ? Else, I've a PR (https://github.com/mpiot/symfony/tree/auto_mapping)

Additional context

Constraint validator "Symfony\Component\Validator\Constraints\DisableAutoMappingValidator" does not exist or is not enabled. Check the "validatedBy" method in your constraint class "Symfony\Component\Validator\Constraints\DisableAutoMapping".

@ogizanagi
Copy link
Contributor

@mpiot : Could you give a look at this patch to see if it solves this issue, please ? #34694

nicolas-grekas added a commit that referenced this issue Dec 10, 2019
…idated (ogizanagi)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Validator] Fix auto-mapping constraints should not be validated

| Q             | A
| ------------- | ---
| Branch?       | 4.4 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | #34672 <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | N/A

As for `Traverse`, I don't think we should add these "constraints" to the list.

I'm also wondering if it really makes sense to have these annotations as constraints. I think it should rather behave like the `GroupSequence` annotation to add the info the generic metadata at loading time, but we don't need to rely on the constraints behavior at all.

Commits
-------

bc53e4b [Validator] Fix auto-mapping constraints should not be validated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants