Bug #49624

Domain Model validators are executed twice

Added by Adrian Föder about 2 years ago. Updated 11 months ago.

Status:Resolved Start date:2013-07-03
Priority:Must have Due date:
Assigned To:Bastian Waidelich % Done:

100%

Category:Validation
Target version:-
PHP Version: Complexity:
Has patch:No Affected Flow version:Flow 2.0.0

Description

when having, for example, a

/**
 * @param SampleDto $sampleDto {fq class name abridged}
 */
public function sampleAction(SampleDto $sampleDto);

and an appropriate Validator for that model placed in Domain\Model\Validator\SampleDtoValidator (i.e. a Domain Model Validator in the sense of [‡]), the validation for it is fired twice on action invocation.

The argument's validator stack looks like the following then:

ConjunctionValidator:
    SampleDtoValidator
    ConjunctionValidator
        GenericObjectValidator
        SampleDtoValidator

as you can see, the SampleDtoValidator is there twice, that's why it's executed twice.

If, however, the Validator is not a Domain Model Validator, means, it's not placed in Domain\Model\Validator; and annotated manually like

/**
 * @param SampleDto $sampleDto {fq class name abridged}
 * @Flow\Validate("$sampleDto", type="Acme\Foobar\Somewhere\SampleDtoValidator")
 */
public function sampleAction(SampleDto $sampleDto);

...it's validated correctly only once.
The validator stack then looks like

ConjunctionValidator:
    SampleDtoValidator
    ConjunctionValidator
        GenericObjectValidator

as you can see, the "inner" conjunction validator only has a GenericObjectValidator now.

[‡] http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/Validation.html#validating-domain-models


Related issues

related to Core - Bug #52607: Domain Model validators are executed twice Resolved 2013-10-08

Associated revisions

Revision b1633ad8
Added by Helmut Hummel 11 months ago

[BUGFIX] Add domain model validators only once

If a domain model validator is present and a controller action accepts
this domain model as argument, the validator is added twice to the
validation tree.

It is added in ValidatorResolver::buildMethodArgumentsValidatorConjunctions()
and in ValidatorResolver::addCustomValidators() which is called from
ValidatorResolver::getBaseValidatorConjunction()

Both methods are called when building the validation tree in
ActionController::initializeActionMethodValidators()

Resolves: #49624
Releases: master, 2.1, 2.0
Change-Id: I1f8902d09f468177d580a7a3d949242cce78313e

Revision 6b38d1f7
Added by Helmut Hummel 11 months ago

[BUGFIX] Add domain model validators only once

If a domain model validator is present and a controller action accepts
this domain model as argument, the validator is added twice to the
validation tree.

It is added in ValidatorResolver::buildMethodArgumentsValidatorConjunctions()
and in ValidatorResolver::addCustomValidators() which is called from
ValidatorResolver::getBaseValidatorConjunction()

Both methods are called when building the validation tree in
ActionController::initializeActionMethodValidators()

Resolves: #49624
Releases: master, 2.2, 2.1
Change-Id: I1f8902d09f468177d580a7a3d949242cce78313e

Revision 296cfc95
Added by Helmut Hummel 11 months ago

[BUGFIX] Add domain model validators only once

If a domain model validator is present and a controller action accepts
this domain model as argument, the validator is added twice to the
validation tree.

It is added in ValidatorResolver::buildMethodArgumentsValidatorConjunctions()
and in ValidatorResolver::addCustomValidators() which is called from
ValidatorResolver::getBaseValidatorConjunction()

Both methods are called when building the validation tree in
ActionController::initializeActionMethodValidators()

Resolves: #49624
Releases: master, 2.2, 2.1
Change-Id: I1f8902d09f468177d580a7a3d949242cce78313e

History

#1 Updated by Karsten Dambekalns almost 2 years ago

  • Category set to Validation

#2 Updated by Bastian Waidelich almost 2 years ago

  • Status changed from New to Accepted
  • Assigned To set to Bastian Waidelich
  • Affected Flow version changed from Git master to Flow 2.0.0

This might be related to #50585

#3 Updated by Helmut Hummel almost 2 years ago

Bastian Waidelich wrote:

This might be related to #50585

I think that is something different.

The issue in this case is, that

ValidatorResolver->buildMethodArgumentsValidatorConjunctions()
adds a domain model validator if present and
ValidatorResolver->buildBaseValidatorConjunction()
calls
ValidatorResolver->addCustomValidators()
which also adds a domain model validator if the class is found.

I suggest to remove the according code from

buildMethodArgumentsValidatorConjunctions

#4 Updated by Gerrit Code Review almost 2 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24174

#5 Updated by Gerrit Code Review almost 2 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24174

#6 Updated by Gerrit Code Review almost 2 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24174

#7 Updated by Markus Klein almost 2 years ago

Also an issue in TYPO3 CMS Extbase!!

#8 Updated by Gerrit Code Review over 1 year ago

Patch set 4 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/24174

#9 Updated by Gerrit Code Review over 1 year ago

Patch set 5 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/24174

#10 Updated by Gerrit Code Review 11 months ago

Patch set 6 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/24174

#11 Updated by Gerrit Code Review 11 months ago

Patch set 1 for branch 2.2 of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/32437

#12 Updated by Gerrit Code Review 11 months ago

Patch set 1 for branch 2.1 of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/32438

#13 Updated by Helmut Hummel 11 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF