#103040Cache an extbase queryResult leads to "Serialization of 'Closure' is not allowed"
Description
$this->cache->set('test', $this->repository->findAll());
will get the Serialization of 'Closure' is not allowed exception.
After some debugging, I found it was caused by the $getService property in /typo3temp/var/cache/code/di/DependencyInjectionContainer_XXXXXXXXXX.php, which was a auto-generated file.
BTW, This bug may relate to Bug #95899.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Files 1
History 4
-
Torben Hansen commented and changed status
NewNeeds Feedback 02/04/24, 18:58 -
Bill Dagou commented and changed attached test.zip 02/05/24, 03:21
Actually, assigning the query result to a variable would not work either, see the test extension, and the reason is what I said.
Maybe we should not call it a “bug”, but caching a result seems to be quite common, maybe just for me. Since this involves in the 3rd-party dependency, and I understand you guys are focusing on v13 development right now, what do you think if someone could doc this issue as a tip or notice somewhere for other developers, maybe https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/Domain/Repository.html, which should not take much time and pressures?
Thank you for your time!
-
Riccardo De Contardi changed status
Needs FeedbackNew 05/24/24, 15:00 -
Torben Hansen commented and changed status
NewClosed 12/13/24, 17:58I created a PR for the docs https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/pull/5143
This issue will therefore be closed now.
You use this wrong, since you try to save the unassigned QueryResult object to the cache. This object contains closures (in the
TYPO3\CMS\Extbase\Persistence\Generic\Queryclass), which leads to this PHP error. Serialization of closures is not allowed in PHP due to context and security considerations.If you assign the query result to a variable, this could work:
$test = $this->repository->findAll(); $this->cache->set('test', $test);I write could work, since extbase has several other places where closures are used and depending on the returned objects in the query result, it may be that also there closures are used.
But in general I would say, this is not a bug.