Skip to content

BUG: Incorrectly missing __sleep for proxy classes with entity properties and/or advices in some cases #3493

@kitsunet

Description

@kitsunet

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

A simple class like this:

class ExampleEvent {

    public function __construct(public SomeDoctrineEntity $doctrineEntity) {}

}

Should strip the doctrine entity (and possible AOP advices on serialize($exampleEventInstance); but it doesn't which leads to serialize errors due to closures used in advices and sometimes entities.

This worked in < 9.0 and was broken with the reworked proxy building.

\Neos\Flow\ObjectManagement\DependencyInjection\ProxyClassBuilder::buildSerializeRelatedEntitiesCode now skips the Flow_serializeRelatedEntities under some conditions (see early returns) which wasn't the case previously. Unfortunately the early returns do not check for entity properties nor for advices (both might be difficult to know at proxy building time).
I think this was done to reduce the amount of proxies we create as we basically generated a __sleep for every class before, however we either need a way to bypass this skip or tighten our conditions to make this waterproof as the resulting error is hard to debug and understand.

A workaround is to add a useless transient property to the respective class ala:

use Neos\Flow\Annotations as Flow;

class ExampleEvent {

    /**
     * Do not remove, this is a workaround for Flows proxy building
     * @Flow\Transient  	
     * @var null 
     */
    protected null $flowProxyFix = null;

    public function __construct(public SomeDoctrineEntity $doctrineEntity) {}

}

Which then triggers the proxy building of the necessary __sleep method.

Expected Behavior

Proxy gets __sleep method to extract unwanted doctrine proxy before serialization.

Steps To Reproduce

No response

Environment

- Flow: 9.0
- PHP: xx

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions