Issue Bug Closed

#109358Record object Serialization exception

George Miller 03/25/26, 11:13 updated 10/02/26, 11:50

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

Files 5

History 5

  1. George Miller commented <span data-processor="relativetime" data-value="2026-03-25T12:57:06+00:00" > 03/25/26, 12:57 </span>

    Sorry, the proposed workaround code is:

    public function __serialize(): array
    {
        foreach ($this->properties as $key => $property) {
            if ($property instanceof RecordPropertyClosure) {
                $this->properties[$key] = $property->instantiate();
            }
            if ($property instanceof LazyFileReferenceCollection
                || $property instanceof LazyRecordCollection
                || $property instanceof LazyFolderCollection) {
                $property->count(); // convert the closure into real data
            }
        }
    
        $objectProperties = get_object_vars($this);
    
        return $objectProperties;
    }
    
    public function __unserialize(array $data): void
    {
        foreach ($data as $propertyName => $propertyValue) {
            $this->{$propertyName} = $propertyValue;
        }
    }
  2. Garvin Hicking commented and changed category status New Needs 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.

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

  4. Georg Ringer commented and changed status Needs Feedback Closed <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.UncachedDetails into a USER_INT. For every USER_INT, the state of the ContentObjectRenderer is 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:cObject converts 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->data unchanged, including the Record object from record-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 serializable Record would 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:cObject converts 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.