Skip to content
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

RequiredValidator missing from 3.4.40 release #36637

Closed
vlahanas opened this issue Apr 30, 2020 · 6 comments
Closed

RequiredValidator missing from 3.4.40 release #36637

vlahanas opened this issue Apr 30, 2020 · 6 comments

Comments

@vlahanas
Copy link

Symfony version(s) affected: 3.4.40

Description
The RequiredValidator is missing from Symfony\Component\Validator\Constraints and breaks the usage of new Constraints\Required()

@stof
Copy link
Member

stof commented Apr 30, 2020

The Required and Optional constraints are special ones meant to be used only inside the Collection one (to decide whether each field in the collection of fields is optional or required). They are not meant to be usable standalone.

@vlahanas vlahanas reopened this Apr 30, 2020
@renjinsk
Copy link

renjinsk commented Apr 30, 2020

Actually, this is how we use it:

$validator   = Validation::createValidator();
$constraints = new Constraints\Collection([
    'theField'  => [
        new Constraints\Required(),
        new Constraints\NotBlank(),
    ],
]);

Correct us if we are wrong..
The "break" was introduced from version 3.4.39 to latest one 3.4.40

@stof
Copy link
Member

stof commented Apr 30, 2020

Correct usage of the Collection constraints looks like that AFAICT:

$constraints = new Constraints\Collection([
    'theField' => new Constraints\Required([
        new Constraints\NotBlank(),
    ])
]);

Also note that fields for which you pass an array of constraints instead of an Optional or Required object get it wrapped in a Required automatically. So your code is equivalent to using a standard Required constraint inside a required field.

@Nyholm
Copy link
Member

Nyholm commented May 3, 2020

Thank you @stof for your explanation.

There is no RequiredValidator in any version of Symfony. They are only annotations used by the Collection.

@Nyholm Nyholm closed this as completed May 3, 2020
@xabbuh
Copy link
Member

xabbuh commented May 12, 2020

see also #36723

@xabbuh
Copy link
Member

xabbuh commented May 21, 2020

see #36894

nicolas-grekas added a commit that referenced this issue May 30, 2020
…tional) constraints (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Validator] never directly validate Existence (Required/Optional) constraints

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36637 #36723
| License       | MIT
| Doc PR        |

Using `Optional` or `Required` like "regular" constraints does not make any sense, but doing so didn't break before #36365. I suggest to ignore them for now and deprecate using them outside the `Collection` constraint in 5.2.

Commits
-------

d333aae never directly validate Existence (Required/Optional) constraints
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

6 participants