Skip to content

Unexpected non-iterable value for to-many relation bug introduced in v2.5.2 or v2.5.3Β #3379

@tristanbes

Description

@tristanbes

API Platform version(s) affected: in version v2.5.2 or v2.5.3 (coulnd't test 2.5.2 as it generated error 500 for the given request)

Description
When I try to get a collection of users, in v2.5.1, it's working well

curl -X GET "http://cosmos.vm/api/users" -H "accept: application/ld+json"

Response:

{
  "@context": "/api/contexts/User",
  "@id": "/api/users",
  "@type": "hydra:Collection",
  "hydra:member": [
    {
      "@id": "/api/users/1",
      "@type": "User",
      "id": 1,
      "email": "[email protected]",
      "roles": [
        "ROLE_TECHPRO_ADMIN",
        "ROLE_USER"
      ],
      "civility": "CIVILITY_MISTER",
      "firstName": "Lily",
      "lastName": "Dibbert",
      "mobile": "+33600000000",
      "phone": "+33400000000",
      "profession": "PROFESSION_DIRECTOR",
      "info": "Un texte d'info plutot court.",
      "avatar": {
        "@id": "/api/media/1",
        "@type": "http://schema.org/MediaObject",
        "title": "avatar 1",
        "filename": "sample_pic.jpeg",
        "mimeType": "image/png",
        "size": 76134831,
        "contentUrl": "http://cosmos.vm/media/cache/resolve/original/fixtures/sample_pic.jpeg"
      },
      "addressIsSameAsSociety": true,
      "address": {
        "@id": "/api/addresses/1",
        "id": 1,
        "street": "30 Rue Sergent Michel Berthet",
        "additional": null,
        "postalCode": "69009",
        "town": "Lyon",
        "country": "France"
      },
      "events": [],
      "createdAt": "2019-03-01T14:00:00+01:00",
      "updatedAt": "2019-04-01T15:55:00+02:00",
      "primaryRole": "ROLE_TECHPRO_OFFICES",
      "sectors": null
    },
.......

How to reproduce
Upgrade to v2.5.3 (the v2.5.2 gave me error 500 when running this request)

curl -X GET "http://cosmos.vm/api/users" -H "accept: application/ld+json"

Response:

Unexpected non-iterable value for to-many relation
{
  "@context": "/api/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "An error occurred",
  "hydra:description": "Unexpected non-iterable value for to-many relation.",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/srv/app/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
      "line": 526,
      "args": []
    },
    {
      "namespace": "ApiPlatform\\Core\\Serializer",
      "short_class": "AbstractItemNormalizer",
      "class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
      "type": "->",
      "function": "getAttributeValue",
      "file": "/srv/app/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
      "line": 183,
      "args": [
        [
          "object",
          "App\\Entity\\User\\User"
        ],
        [
          "string",
          "sectors"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "api_sub_level": [
              "boolean",
              true
            ],
            "jsonld_has_context": [
              "boolean",
              true
            ],
            "iri": [
              "string",
              "/api/users/1"
            ],
            "api_normalize": [
              "boolean",
              true
            ],
            "cache_key": [
              "string",
              "0048d7cbc86087b8ea231aa42a2ffe2f"
            ],
            "circular_reference_limit_counters": [
              "array",
              {
                "000000003a548a7d0000000071563da7": [
                  "integer",
                  1
                ]
              }
            ],
            "api_attribute": [
              "string",
              "sectors"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\Serializer\\Normalizer",
      "short_class": "AbstractObjectNormalizer",
      "class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
      "type": "->",
      "function": "normalize",
      "file": "/srv/app/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
      "line": 151,
      "args": [
        [
          "object",
          "App\\Entity\\User\\User"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "api_sub_level": [
              "boolean",
              true
            ],
            "jsonld_has_context": [
              "boolean",
              true
            ],
            "iri": [
              "string",
              "/api/users/1"
            ],
            "api_normalize": [
              "boolean",
              true
            ],
            "cache_key": [
              "string",
              "0048d7cbc86087b8ea231aa42a2ffe2f"
            ],
            "circular_reference_limit_counters": [
              "array",
              {
                "000000003a548a7d0000000071563da7": [
                  "integer",
                  1
                ]
              }
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatform\\Core\\Serializer",
      "short_class": "AbstractItemNormalizer",
      "class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
      "type": "->",
      "function": "normalize",
      "file": "/srv/app/vendor/api-platform/core/src/JsonLd/Serializer/ItemNormalizer.php",
      "line": 80,
      "args": [
        [
          "object",
          "App\\Entity\\User\\User"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "api_sub_level": [
              "boolean",
              true
            ],
            "jsonld_has_context": [
              "boolean",
              true
            ],
            "iri": [
              "string",
              "/api/users/1"
            ],
            "api_normalize": [
              "boolean",
              true
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatform\\Core\\JsonLd\\Serializer",
      "short_class": "ItemNormalizer",
      "class": "ApiPlatform\\Core\\JsonLd\\Serializer\\ItemNormalizer",
      "type": "->",
      "function": "normalize",
      "file": "/srv/app/vendor/symfony/serializer/Serializer.php",
      "line": 152,
      "args": [
        [
          "object",
          "App\\Entity\\User\\User"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "api_sub_level": [
              "boolean",
              true
            ],
            "jsonld_has_context": [
              "boolean",
              true
            ],
            "iri": [
              "string",
              "/api/users/1"
            ],
            "api_normalize": [
              "boolean",
              true
            ]
          }
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\Serializer",
      "short_class": "Serializer",
      "class": "Symfony\\Component\\Serializer\\Serializer",
      "type": "->",
      "function": "normalize",
      "file": "/srv/app/vendor/api-platform/core/src/Hydra/Serializer/CollectionNormalizer.php",
      "line": 87,
      "args": [
        [
          "object",
          "App\\Entity\\User\\User"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "api_sub_level": [
              "boolean",
              true
            ],
            "jsonld_has_context": [
              "boolean",
              true
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatform\\Core\\Hydra\\Serializer",
      "short_class": "CollectionNormalizer",
      "class": "ApiPlatform\\Core\\Hydra\\Serializer\\CollectionNormalizer",
      "type": "->",
      "function": "normalize",
      "file": "/srv/app/vendor/api-platform/core/src/Hydra/Serializer/PartialCollectionViewNormalizer.php",
      "line": 55,
      "args": [
        [
          "object",
          "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "api_sub_level": [
              "boolean",
              true
            ],
            "jsonld_has_context": [
              "boolean",
              true
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatform\\Core\\Hydra\\Serializer",
      "short_class": "PartialCollectionViewNormalizer",
      "class": "ApiPlatform\\Core\\Hydra\\Serializer\\PartialCollectionViewNormalizer",
      "type": "->",
      "function": "normalize",
      "file": "/srv/app/vendor/api-platform/core/src/Hydra/Serializer/CollectionFiltersNormalizer.php",
      "line": 73,
      "args": [
        [
          "object",
          "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatform\\Core\\Hydra\\Serializer",
      "short_class": "CollectionFiltersNormalizer",
      "class": "ApiPlatform\\Core\\Hydra\\Serializer\\CollectionFiltersNormalizer",
      "type": "->",
      "function": "normalize",
      "file": "/srv/app/vendor/symfony/serializer/Serializer.php",
      "line": 152,
      "args": [
        [
          "object",
          "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\Serializer",
      "short_class": "Serializer",
      "class": "Symfony\\Component\\Serializer\\Serializer",
      "type": "->",
      "function": "normalize",
      "file": "/srv/app/vendor/symfony/serializer/Serializer.php",
      "line": 125,
      "args": [
        [
          "object",
          "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\Serializer",
      "short_class": "Serializer",
      "class": "Symfony\\Component\\Serializer\\Serializer",
      "type": "->",
      "function": "serialize",
      "file": "/srv/app/vendor/api-platform/core/src/EventListener/SerializeListener.php",
      "line": 95,
      "args": [
        [
          "object",
          "ApiPlatform\\Core\\Bridge\\Doctrine\\Orm\\Paginator"
        ],
        [
          "string",
          "jsonld"
        ],
        [
          "array",
          {
            "groups": [
              "array",
              [
                [
                  "string",
                  "read"
                ],
                [
                  "string",
                  "user"
                ],
                [
                  "string",
                  "address"
                ]
              ]
            ],
            "operation_type": [
              "string",
              "collection"
            ],
            "collection_operation_name": [
              "string",
              "get"
            ],
            "resource_class": [
              "string",
              "App\\Entity\\User\\User"
            ],
            "input": [
              "null",
              null
            ],
            "output": [
              "null",
              null
            ],
            "request_uri": [
              "string",
              "/api/users"
            ],
            "uri": [
              "string",
              "http://cosmos.vm/api/users"
            ],
            "resources": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ],
            "exclude_from_cache_key": [
              "array",
              [
                [
                  "string",
                  "resources"
                ],
                [
                  "string",
                  "resources_to_push"
                ]
              ]
            ],
            "resources_to_push": [
              "object",
              "ApiPlatform\\Core\\Serializer\\ResourceList"
            ]
          }
        ]
      ]
    },
    {
      "namespace": "ApiPlatform\\Core\\EventListener",
      "short_class": "SerializeListener",
      "class": "ApiPlatform\\Core\\EventListener\\SerializeListener",
      "type": "->",
      "function": "onKernelView",
      "file": "/srv/app/vendor/symfony/event-dispatcher/Debug/WrappedListener.php",
      "line": 126,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
        ],
        [
          "string",
          "kernel.view"
        ],
        [
          "object",
          "Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher\\Debug",
      "short_class": "WrappedListener",
      "class": "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener",
      "type": "->",
      "function": "__invoke",
      "file": "/srv/app/vendor/symfony/event-dispatcher/EventDispatcher.php",
      "line": 264,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
        ],
        [
          "string",
          "kernel.view"
        ],
        [
          "object",
          "Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher",
      "short_class": "EventDispatcher",
      "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
      "type": "->",
      "function": "doDispatch",
      "file": "/srv/app/vendor/symfony/event-dispatcher/EventDispatcher.php",
      "line": 239,
      "args": [
        [
          "array",
          [
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ]
          ]
        ],
        [
          "string",
          "kernel.view"
        ],
        [
          "object",
          "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher",
      "short_class": "EventDispatcher",
      "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
      "type": "->",
      "function": "callListeners",
      "file": "/srv/app/vendor/symfony/event-dispatcher/EventDispatcher.php",
      "line": 73,
      "args": [
        [
          "array",
          [
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ],
            [
              "object",
              "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
            ]
          ]
        ],
        [
          "string",
          "kernel.view"
        ],
        [
          "object",
          "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher",
      "short_class": "EventDispatcher",
      "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
      "type": "->",
      "function": "dispatch",
      "file": "/srv/app/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php",
      "line": 168,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
        ],
        [
          "string",
          "kernel.view"
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\EventDispatcher\\Debug",
      "short_class": "TraceableEventDispatcher",
      "class": "Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher",
      "type": "->",
      "function": "dispatch",
      "file": "/srv/app/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 151,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpKernel\\Event\\ViewEvent"
        ],
        [
          "string",
          "kernel.view"
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "HttpKernel",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "->",
      "function": "handleRaw",
      "file": "/srv/app/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 68,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpFoundation\\Request"
        ],
        [
          "integer",
          1
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "HttpKernel",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "->",
      "function": "handle",
      "file": "/srv/app/vendor/symfony/http-kernel/Kernel.php",
      "line": 201,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpFoundation\\Request"
        ],
        [
          "integer",
          1
        ],
        [
          "boolean",
          true
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "Kernel",
      "class": "Symfony\\Component\\HttpKernel\\Kernel",
      "type": "->",
      "function": "handle",
      "file": "/srv/app/public/index.php",
      "line": 25,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpFoundation\\Request"
        ]
      ]
    }
  ]
}

Additional Context

As I understand from the trace, ApiPlatform tries to call getSectors() from the User::class. This is a problem, because this method only exists inside TechproCommercial::class and TechproAgent:class.

I checked that no reference of sectors inside the User::class is found, so I don't understand why this is happening.

Our user class has 2 inherited sub Users

/**
 * @ORM\Table(name="app_user")
 * @ORM\Entity(repositoryClass="App\Repository\User\UserRepository")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="discriminator", type="string")
 * @ORM\DiscriminatorMap({
 *     "user" = "User",
 *     User::DISCRIMINATOR_LABEL_COMMERCIAL = "TechproCommercial",
 *     User::DISCRIMINATOR_LABEL_AGENT = "TechproAgent"
 * })
 * @ApiResource(
 *     collectionOperations={
 *          "get"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "post"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"}
 *     },
 *     itemOperations={
 *          "get"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "put"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "delete"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"}
 *     },
 *     normalizationContext={"groups"={"read", "user", "address"}},
 *     denormalizationContext={"groups"={"write", "user", "address"}}
 * )
 * @ApiFilter(SearchFilter::class, properties={"email": "partial", "company.id": "exact"})
 * @UniqueEntity("email", repositoryMethod="findByEmailInArray")
 */
class User implements UserInterface, PasswordResettableInterface, \Serializable
{
...
}
/**
 * @ORM\Entity(repositoryClass="App\Repository\User\TechproCommercialRepository")
 * @ApiResource(
 *     collectionOperations={
 *          "get"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "post"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"}
 *     },
 *     itemOperations={
 *          "get"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "put"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "delete"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"}
 *     }
 * )
 */
class TechproCommercial extends User implements HasSectorsInterface
{
    use HasSectorsTrait;

    /**
     * @var Collection<int,Sector>
     * @ORM\ManyToMany(targetEntity="App\Entity\Sector", inversedBy="techproCommercials")
     * @Groups({"user"})
     */
    protected $sectors;

    public function __construct()
    {
        parent::__construct();
        $this->sectors = new ArrayCollection();
    }

    public function getRoles(): array
    {
        return \array_merge(parent::getRoles(), [Role::TECHPRO_COMMERCIAL]);
    }

    public function getPrimaryRole(): string
    {
        return Role::TECHPRO_COMMERCIAL;
    }
/**
 * @ORM\Entity(repositoryClass="App\Repository\User\TechproAgentRepository")
 * @ApiResource(
 *     collectionOperations={
 *          "get"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "post"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"}
 *     },
 *     itemOperations={
 *          "get"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "put"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"},
 *          "delete"={"access_control"="is_granted('ROLE_TECHPRO_ADMIN')"}
 *     }
 * )
 */
class TechproAgent extends User implements HasSectorsInterface
{
    use HasSectorsTrait;

    /**
     * @var Collection<int,Sector>
     * @ORM\ManyToMany(targetEntity="App\Entity\Sector", inversedBy="techproAgents")
     * @Groups({"user"})
     */
    protected $sectors;

    public function __construct()
    {
        parent::__construct();
        $this->sectors = new ArrayCollection();
    }

    public function getRoles(): array
    {
        return \array_merge(parent::getRoles(), [Role::TECHPRO_AGENT_VRP]);
    }

    public function getPrimaryRole(): string
    {
        return Role::TECHPRO_AGENT_VRP;
    }
}

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