Skip to content

[Validator] Ensure nested validations for Collections happen in a separate context #14786

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
wants to merge 1 commit into from
Closed

[Validator] Ensure nested validations for Collections happen in a separate context #14786

wants to merge 1 commit into from

Conversation

evanpurkhiser
Copy link

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14639
License MIT
Doc PR n/a

@evanpurkhiser
Copy link
Author

Ping @fabpot

@fabpot
Copy link
Member

fabpot commented Jun 9, 2015

ping @symfony/deciders

@stof
Copy link
Member

stof commented Jun 10, 2015

I would like a validation of @webmozart to be sure it is the right fix. I'm not sure the ExecutionContext is meant to be clonable (and different implementations might not share the same ViolationList when cloning btw, which would break this fix)

@evanpurkhiser
Copy link
Author

Hmm, I think this may have some relation to #11412. Looking at the changes in that fix, indeed maybe cloning the context might not be the right solution.

Hopefully @webmozart can comment :-)

@fabpot
Copy link
Member

fabpot commented Jun 30, 2015

@webmozart Can you tell us your point of view on this PR?

@xabbuh
Copy link
Member

xabbuh commented Jul 2, 2015

ping @webmozart

1 similar comment
@reket
Copy link

reket commented Nov 13, 2015

ping @webmozart

@evanpurkhiser
Copy link
Author

Ping @webmozart on this again :-)

@javiereguiluz javiereguiluz added Bug and removed Ready labels Mar 3, 2016
@fabpot
Copy link
Member

fabpot commented Mar 4, 2016

@webmozart The change made in this PR is "simple" enough but we really need your help to validate that this is indeed the right way.

@@ -60,7 +60,7 @@ public function validate($value, Constraint $constraint)
if (count($fieldConstraint->constraints) > 0) {
if ($context instanceof ExecutionContextInterface) {
$context->getValidator()
->inContext($context)
->inContext(clone $context)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution doesn't work. Now all constraints thrown by the validators in the Collection constraint will be added to the cloned context and not appear in the current context (which is the point of calling inContext()).

@webmozart
Copy link
Contributor

@fabpot Thanks for the ping. Unfortunately this solution would bringe more problems than it would solve. The proper solution is to reset the constraint in the ExecutionContext to the previous one after the nested validation call. We already do the same for the other context properties.

We need to add a new method getConstraint() to ExecutionContext in order to do this. When we switch to 4.0, the method should be added to ExecutionContextInterface as well.

@webmozart
Copy link
Contributor

Status: Needs Work

@fabpot
Copy link
Member

fabpot commented Jun 9, 2016

Closing as @webmozart mentioned that this is not something we can merge anyway. As there is a corresponding issue, this will still be linked there in case someone want to work on @webmozart suggestion.

@xabbuh
Copy link
Member

xabbuh commented Nov 28, 2016

see #20664 for an alternative approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants