Bug #50585

Validation fails if nested properties of same type are present

Added by Martin Lipp over 8 years ago. Updated over 7 years ago.

Status:
Resolved
Priority:
Must have
Category:
Validation
Target version:
-
Start date:
2013-07-31
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

The GenericObjectValidator dumps all prior calculated validation results, when validating a nested property which has the same class name as the validated object.

Quick example:

class Office {
    /**
     * @var string
     * @Flow\Validate(type="StringLength", options={ "minimum"=3, "maximum"=100 })
     * @Flow\Validate(type="NotEmpty")
     * @ORM\Column(length=100)
     */
    protected $title;

    /**
     * @var \Doctrine\Common\Collections\Collection<\Company\Project\Domain\Model\OpeningHours>
     * @ORM\OneToMany(mappedBy="office")
     */
    protected $openingHours;

    ...

class OpeningHours {
    /**
     * @var \Company\Project\Domain\Model\Office
     * @ORM\ManyToOne(inversedBy="openingHours")
     */
    protected $office;

    ...

When creating a new Office with a form including one ore more openingHours, all validation errors of properties defined prior to $openingHours are dumped and therefore not displayed as errors. If no other validation error after the $openingHours property occurs, the createAction is executed with no error messages (but not persisted, seems that the validation here works). In the above example an empty $title would pass the validation.

I've tracked it down to the GenericObjectValidator and the ValidatorResolver:
The ValidatorResolver only creates a new baseValidatorConjunction, if none exists for this class name. Otherwise it uses the existing one. Since the GenericObjectValidator's validate() method resets its member $this->result on every call, all results of prior Office properties are deleted as soon as it comes to the validation of the openingHours' $office property.
This does not happen in one of my older projects (with FLOW3 1.1), because there the GenericObjectValidator does not store its results in a member variable, but only calculates it inside the method.
Also it only seems to happen inside collections.


Related issues

Related to TYPO3.Flow - Task #46340: Improve validation to speed up FlowResolved2013-03-15

Actions
Related to TYPO3 Core - Bug #91029: Validation fails if nested properties of same type are presentNew2020-04-14

Actions

Also available in: Atom PDF