#98190Extbase fails to resolve chained validations
Description
use TYPO3\CMS\Extbase\Annotation\Validate;
class Parent extends AbstractEntity
{
protected Child $child;
}
class Child extends AbstractEntity
{
/**
* @Validate("StringLength", options={"minimum": 1, "maximum": 80})
*/
public string $title = '';
}
class ParentController extends ActionController
{
public function showAction(Parent $parent): ResponseInterface
{
// ...
}
}
Action Parent.show gets argument of type Parent, which has a non-accessible property to type Child, which has a validation rule of a property. Following the validation chain is correct in general, unless some part of it cannot be accessed (which is protected property Parent::$child in this example).
The result is a corresponding exception:
(1/1) #1546632293 RuntimeException Could not get value of property "Olly\Model\Domain\Model\Parent::child", make sure the property is either public or has a getter getChild(), a hasser hasChild() or an isser isChild().
In case validation for internal values is desired/expected, this probably would be something for reflection.
In case developers would “need to adjust their code”, current RuntimeException (#1546632293) is semantically wrong, it has to be a LogicException instead.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[BUGFIX] Extbase fails to resolve chained validations Resolves: #98190 Releases: main
Related issues 1
History 4
-
Oliver Hader changed Related to #98148 <span data-processor="relativetime" data-value="2022-08-23T12:52:08+00:00" > 08/23/22, 12:52 </span>
-
Oliver Hader changed status
NewAccepted <span data-processor="relativetime" data-value="2022-08-23T12:52:23+00:00" > 08/23/22, 12:52 </span> -
Benni Mack changed Sprint Focus Stabilization Sprint <span data-processor="relativetime" data-value="2023-06-06T13:08:49+00:00" > 06/06/23, 13:08 </span>
Still reproducible on main (15.0.0-dev, fd25ec1e9e6): a protected model-typed property without accessor, whose class has validators, throws
RuntimeException#1546632293fromAbstractGenericObjectValidator::getPropertyValue(). Checked by callingValidatorResolver::getBaseValidatorConjunction()->validate()directly, not through a full request.Since this report, there are explicit ways to opt out:
#[IgnoreValidation]on the property (main only, #111134)#[Transient](main, 14.3 and 13.4, #91727; deprecated for this purpose on main)Adding a getter also avoids the exception. The default case is unchanged, and the exception is still a
RuntimeException.Open question: is the exception the intended behaviour now that
#[IgnoreValidation]exists? If so, this could be reduced to changing the exception type and pointing to the attribute in its message. Skipping inaccessible properties silently would drop validation that fails loudly today.