Bug #95899


Try to cache an extbase queryResult leads to "Serialization of 'Closure' is not allowed"

Added by Alex Kellner over 2 years ago. Updated over 1 year ago.

Should have
Target version:
Start date:
Due date:
% Done:


Estimated time:
TYPO3 Version:
PHP Version:
Is Regression:
Sprint Focus:


I would like to add some caching into my backend views in lux to speed up diagrams.

But in TYPO3 11.5.2 together (with PHP 7.4 or 8.0) I always ran into the exception:
"Serialization of 'Closure' is not allowed"

An example extbase model could be very simple (without any relations or Lazy Loading) with just one string property and extend AbstractEntity. Also the repository function is without magic here:

$query = $this->createQuery();
$query->setOrderings(['uid' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING]);
return $query->execute();

If I try to cache the result like

$cacheInstance = GeneralUtility::makeInstance(CacheManager::class)->getCache('bar');
$cacheInstance->set('foo', $queryResult, ['bar'], 100000);

The error is happening:

Any ideas?


closure.png (102 KB) closure.png Alex Kellner, 2021-11-07 12:47
File.php (3.84 KB) File.php Example model Marvin Buchmann, 2022-12-21 08:45
SerializableEntityInterface.php (451 Bytes) SerializableEntityInterface.php Interface Marvin Buchmann, 2022-12-21 08:45
SerializableEntityTrait.php (1.42 KB) SerializableEntityTrait.php Trait Marvin Buchmann, 2022-12-21 08:45

Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Bug #91364: Extbase/CachingFramework - Serialization on 'Closure' is not allowedNew2020-05-12

Actions #1

Updated by Alex Kellner over 2 years ago

Update: Using an array instead of QueryResult helps as workarround:


Actions #2

Updated by Benni Mack over 1 year ago

  • Related to Bug #91364: Extbase/CachingFramework - Serialization on 'Closure' is not allowed added

Updated by Marvin Buchmann over 1 year ago

Alex Kellner wrote in #note-1:

Update: Using an array instead of QueryResult helps as workaround:

Thanks! I had the same problem when trying to cache my QueryResult. But the workaround only seems to work if the model doesn't contain any (lazy) ObjectStorage properties (tested in TYPO3 11.5).
Since I needed those, I created a workaround that works for all my models. I got the idea from this fix

It's basically just an interface and a trait unsetting all ObjectStorage properties by default when serialized and calling the initializeObject method of the object when unserialized. If not implemented, it provides one that just initializes the ObjectStorage properties empty.

The model has to implement the interface and use the trait. Then it's serializable and therefore cacheable. :) At least in my use cases.
I attached an example model, the interface and the trait.

I know traits are not really desirable, but the methods could be implemented in the AbstractEntity class if it works for all other use cases aswell. Then every extbase model would be cacheable by default, which I would really appreciate.


Also available in: Atom PDF