Skip to content

Conflict between original_data cloning and application cloning in WriteListener #6362

Closed
@ZZromanZZ

Description

@ZZromanZZ

API Platform version(s) affected: 3.3.2

Description

I noticed that in PR #6102 was added feature to clone original data in Symfony WriteListener. This orignal data are further used to generate Content-Location header.
However when someone already use __clone() on Entity (original data object) to provide some other bussiness functionality and resets id property (for example):

public function __clone()
{
    $this->id = null;
}

Generating Content Location header fails with Metadata RuntimeException No identifier value found, did you forget to persist the entity?

image

How to reproduce
Simple GET /api/entity/{id} with __clone() method setting ID property to null results to RuntimeException
Of course, this issue applies only for Symfony (use_symfony_listeners: true)

Possible Solution

I'm not sure why is cloning original data even needed.

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