Skip to content

Serialization issue with frankenphp worker mode due to normalizer cache #7868

@julien-maurel

Description

@julien-maurel

API Platform version(s) affected: 4.3.1

Description
2 APIs:

  • 1 : use DTO A as output
  • 2 : use DTO B as output

DTO B has a property that is an array of DTO A

On non worker mode:

  • call API 1 : ItemNormalizer is used on DTO A
  • call API 2 : ObjectNormalizer is used on the array of DTO A

Difference is produce by AbstractItemNormalizer:115, on API 1 condition return true and on API 2 false

        if (($context['output']['class'] ?? null) === $class) {
            return true;
        }

On worker mode:

  • call API 1 : ItemNormalizer is used on DTO A and result is set on serializer cache
  • call API 2 : because previous call cache ItemNormalizer as true for DTO A in normalizer cache of serializer, ItemNormalizer is used again and produce this error
    ApiPlatform\Metadata\ResourceClassResolver::isResourceClass(): Argument #1 ($type) must be of type string, null given, called in vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php on line 461 because $context['resource_class'] is unset before serialization of the array of DTO A

Tested on jsonLD and json formats

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions