core icon indicating copy to clipboard operation
core copied to clipboard

AbstractItemNormalizer::getFactoryOptions() can return the wrong serialization groups (with FrankenPHP worker mode)

Open neluba opened this issue 1 year ago • 0 comments

API Platform version(s) affected: 3.3.12

Description

Hey, this is my issue report and the problem is a litte hard to describe so I hope you can still follow me. I started to switch to FrankenPHP recently on a test system for a project and noticed that I got different results for the same API requests for one of API resources, because the serialization groups are getting carried over from previous requests.

From what I can tell seems the $localFactoryOptionsCache to be the issue because it's not getting cleared between requests and the 'operation_name' and 'root_operation_name' is always empty which results in a simple class name as the $operationCacheKey.


How to reproduce

I have two API resources. The first one uses a serialization group 'read' for all requests and implements the second API resource as a readableLink and passes on the serialization group. The second resource doesn't use the serialization group and always outputs all fields for every request.

Starting a new worker and requesting the resource with the serialization groups corrupts the cache on the same worker for requests for the second ressource.


Possible Solution

Either clearing the cache between requests or using a different cache key. I don't know if this issue can happen on one entity in the same request. If it cant, than reseting the cache should be enough.

I turned off the worker mode for now.


Additional Context

Dump of ($operationCacheKey . $suffix) and $this->localFactoryOptionsCache on a fresh worker in line: AbstractitemNormalizer.php:654

Requested "ImportProvider" without groups

image

Same dump with corrupted cache. "TripPriceTemplate" was requested before which has a "ImportProvider" property with the group "read". This dump shows the request for "ImportProvider" without groups afterwards.

image

neluba avatar Sep 13 '24 09:09 neluba