Project

General

Profile

Actions

Bug #103040

open

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

Added by Bill Dagou 3 months ago. Updated 3 months ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2024-02-05
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

test.zip (8.78 KB) test.zip Bill Dagou, 2024-02-05 02:56
Actions #1

Updated by Torben Hansen 3 months ago

  • 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.

Actions #2

Updated by Bill Dagou 3 months ago

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!

Actions

Also available in: Atom PDF