Bug #103040
open
Cache an extbase queryResult leads to "Serialization of 'Closure' is not allowed"
Added by Bill Dagou 10 months ago.
Updated 6 months ago.
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.
Files
- Status changed from New to Needs Feedback
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\Query
class), 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.
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!
- Status changed from Needs Feedback to New
Also available in: Atom
PDF