#109358Record object Serialization exception
Description
Error description
I have an uncached controller whose fluid template uses a RecordTransformationProcessor . When the controller is called, an exception is thrown (‘Serialisation of Closure is not allowed’). The exception is thrown in TYPO3\CMS\Frontend\ContentObject\UserInternalContentObject.
Temporary workaround
The following serialisation method in TYPO3\CMS\Core\Domain\Record provides a temporary fix for the error:
public function __serialize(): array
{
$a = $this->toArray();
foreach ($a as $property) {
if ($property instanceof LazyFileReferenceCollection
|| $property instanceof LazyRecordCollection
|| $property instanceof LazyFolderCollection) {
$property->count(); // convert the closure into real data
}
}
return $a;
}
But this means that the performance benefit of lazy records is lost.
Reviews 1
Related issues 1
Files 5
History 5
-
Garvin Hicking commented and changed category status
NewNeeds Feedback <span data-processor="relativetime" data-value="2026-03-25T19:21:32+00:00" > 03/25/26, 19:21 </span>Could you maybe check out if https://review.typo3.org/c/Packages/TYPO3.CMS/+/91670 is something that allows this to work better in TYPO3 v14?
I’m afraid a change to this in v13 might be too invasive, so it would help at least to know if it is resolved for v14.
-
George Miller commented and changed attached ext_localconf.php attached UncachedController.php attached Home.html attached setup.typoscript <span data-processor="relativetime" data-value="2026-03-30T15:37:20+00:00" > 03/30/26, 15:37 </span>
The same error occurs in this version as well (14.1.1). I have put together a minimal controller setup that allows the error to be reproduced quickly.
There is a FLUIDTEMPLATE containing a record-transformation-dataprocessor. In the associated Fluid, an uncached controller is called, which is passed all the Fluid’s variables, including the transformation record; when this controller is called, an exception occurs. -
Georg Ringer commented and changed status
Needs FeedbackClosed <span data-processor="relativetime" data-value="2026-10-02T11:50:27+00:00" > 10/02/26, 11:50 </span>Thanks for the detailed report and the minimal setup, that made it easy to follow. The exception is caused by
data="{_all}", not by the record itself, and the proposed__serialize()workaround would not actually help. Here is why.Where it fails
An uncached Extbase action turns
lib.UncachedDetailsinto aUSER_INT. For everyUSER_INT, the state of theContentObjectRendereris serialized into the page cache, so that the plugin can be rendered later outside of the cached page (AbstractContentObject::generateNotCachedContentPlaceholder()):'cObjData' => serialize($this->cObj->getState()),That state includes
$cObj->data, the array passed via<f:cObject data="...">.Why {_all} breaks it
f:cObjectconverts a record that is passed directly into its raw array:$data = $data instanceof RecordInterface ? ($data->getRawRecord()?->toArray(true) ?? $data->toArray()) : ...;{_all}is an array though, so every template variable ends up in$cObj->dataunchanged, including theRecordobject fromrecord-transformation. Serializing that object fails because of the closures used for lazy loading.Why making Record serializable is not the solution
- When the uncached part is rendered, the state is read back with
unserialize($cObjData, ['allowed_classes' => false]). Even a serializableRecordwould arrive in your plugin as__PHP_Incomplete_Class, so it could not be used anyway. - Resolving all lazy properties in
__serialize()removes the performance benefit of lazy loading, as you noted yourself. - Core deliberately keeps this state scalar-only. See #108803 for the most recent step in that direction.
How to solve it
Pass only what the plugin needs. Passing the record directly works, because
f:cObjectconverts it to the raw database row:<f:cObject typoscriptObjectPath="lib.UncachedDetails" data="{record}" />Alternatively, pass selected scalar values, or fetch the record inside the controller based on the current content element or page.
As this works as designed, I’m closing the issue. If you think the error message should be clearer in this situation, feel free to open a new issue for that.
- When the uncached part is rendered, the state is read back with
-
Georg Ringer changed Related to #107152 <span data-processor="relativetime" data-value="2026-10-02T11:53:43+00:00" > 10/02/26, 11:53 </span>
Sorry, the proposed workaround code is: