Bug #89971
closedExtbase validation broken since merge of "58833: [BUGFIX] Keep existing validation errors for recursive domain relations"
0%
Description
Change https://review.typo3.org/c/Packages/TYPO3.CMS/+/58833 breaks usage of extbase validation in at least TYPO3 8.7.
With PHP 7.0 I see weird effects for this code:¶
class MyAbstractModel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {} class MyModel extends MyAbstractModel { /** * @var int * @validate \Vendor\Extension\Domain\Validator\NumberRangeNull (minimum = 0, maximum = 15) */ protected $myInteger; }
$objectsData = [16,0]; foreach ($objectsData as $objectData) { $myModel = $this->objectManager->get(Domain\Model\MyModel::class); $myModel->setMyInteger($objectData); $validator = $this->validatorResolver->getBaseValidatorConjunction(Domain\Model\MyModel::class); $validatorResults = $validator->validate($object); var_dump($myModel->getMyInteger()); # returns 16 for first $myModel and 0 for second $myModel var_dump($validatorResults); # returns object(TYPO3\CMS\Extbase\Error\Result)#112081 for BOTH $myModel (!) }
Running the code with change #58833 the $validatorResults
for the second object contain exactly the SAME object(TYPO3\CMS\Extbase\Error\Result)#112081
stating that the second object is invalid while it is not.
If I revert change #58833 the code runs without issues.
With PHP 7.2 the effects are even worse (!):¶
During validation of a certain object the PHP CLI process executing eats up all RAM and dies:
32211 Killed /home/mysite/www/typo3/sysext/core/bin/typo3 $@
syslog:
winbindd invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0 [ pid ] uid tgid total_vm rss nr_ptes swapents oom_score_adj name [32211] 0 32211 3154075 1901446 6144 795905 0 php Out of memory: Kill process 32211 (php) score 633 or sacrifice child Killed process 32211 (php) total-vm:12616300kB, anon-rss:7605736kB, file-rss:48kB
Updated by Stephan Großberndt almost 5 years ago
- Due date set to 2018-03-20
- Start date changed from 2019-12-17 to 2018-03-20
- Follows Bug #84475: Validation skipped for domain-record with circular relationship on itself on submitting nested form added
Updated by Stephan Großberndt almost 5 years ago
- Due date deleted (
2018-03-20) - Start date deleted (
2018-03-20)
I guess this might be happening as new objects are being generated which do not contain a UID yet. Could this be an issue?
Updated by Markus Klösges almost 5 years ago
Can't reproduce on current master, nor on 9.5
I'm not able to easily run functionals on my local machine for 8.7.
public function regressionTest() { $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class); $chars = implode('', range(0,81)); $objectsData = [$chars, '2']; $validationResults = []; foreach ($objectsData as $key => $objectData) { /** @var Blog $myModel */ $myModel = $this->objectManager->get(Blog::class); $myModel->setTitle($objectData); $myModel->setDescription('non-empty'); self::assertEquals($objectData, $myModel->getTitle()); $validator = $this->validatorResolver->getBaseValidatorConjunction(Blog::class); $validatorResults = $validator->validate($myModel); self::assertEquals($objectsData[$key], $myModel->getTitle()); $validationResults[] = $validatorResults; } self::assertNotSame($validationResults[0], $validationResults[1]); self::assertTrue($validationResults[0]->hasErrors()); self::assertFalse($validationResults[1]->hasErrors()); }
works fine when using the Blog-Extension Fixture (which has a Stringlength(0,80) Validator on the title field.
Updated by Markus Klösges almost 5 years ago
Didn't really ment to push that patch - but did so acidentially.
https://review.typo3.org/c/Packages/TYPO3.CMS/+/62722
Updated by Gerrit Code Review almost 5 years ago
- Status changed from New to Under Review
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62722
Updated by Alexander Schnitzler over 4 years ago
- Status changed from Under Review to Rejected
- Priority changed from Must have to -- undefined --
Rejected due to the fact that this issue couldn't be reproduced by users. Feel free to reopen if this bug can be reproduced.
Updated by Stephan Großberndt over 4 years ago
- Status changed from Rejected to New
Updated by Georg Ringer over 4 years ago
- Related to Bug #91029: Validation fails if nested properties of same type are present added
Updated by Stephan Großberndt over 4 years ago
- Status changed from New to Rejected
I was backtracing to out-of-memory issue and was able to fix this in my extension, which has a very complex data model with lots of relations.
It has a method getMyRelatedObjects
in a Model to fetch myRelatedObjects
but it does not return their ObjectStorage
, instead it converts it to an array in order to sort it and creates a new ObjectStorage
to add the related objects in the correct order:
/** * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\MyRelatedObject> */ public function getMyRelatedObjects() { $myRelatedObjects = ArraySort::sortByPropertyX($this->myRelatedObjects->toArray(), QueryInterface::ORDER_DESCENDING); $sortedStorage = new ObjectStorage(); foreach ($myRelatedObjects as $myRelatedObject) { $sortedStorage->attach($myRelatedObject); } return $sortedStorage; }
Apparently extbase is calling the methods named like the properties by reflection during validation which causes these issues. By renaming the method getMyRelatedObjects
to getMyRelatedObjectsSorted
, adding a new getMyRelatedObjects
method which simply returns the original $this->myRelatedObjects
and switching all places where I need the related objects in a sorted order to use getMyRelatedObjectsSorted
I was able to fix the memory issue.
I set this issue to rejected again as I cannot reproduce the issue of $validatorResults returning the SAME object(TYPO3\CMS\Extbase\Error\Result)#112081
for a second object anymore with current data.