Core: [2.4-beta.2] DataProvider with subResource: the uri leads to a 500 because The manager for my Entity must be an EntityManager

Created on 27 Feb 2019  路  1Comment  路  Source: api-platform/core

Hi,

i have a simple entity that define an endpoint and that is not a Doctrine Entity. It declares some properties and one of them is a subResource. This mapping of this subResource is a class that has both Doctrine nd ApiPlatform annotation (it's a light classe and it seems a quicker solution without impact).
If i call the sub resource, then i have a 500 which is logic because:
in api-platform\core\src\Bridge\Doctrine\Orm\SubresourceDataProvider.php::line 139 it does a $this->managerRegistry->getManagerForClass(EntityClass) where the EntityClass is the Api definition, not the Doctrine Entity, so no Manager is available.

How should we deal with this of error ?

Here is the stack:
```
{
"type": "https://tools.ietf.org/html/rfc2616#section-10",
"title": "An error occurred",
"detail": "The manager for App\Api\EndPoint\Patients\ByUser must be an EntityManager.",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "my-project\symfony\vendor\api-platform\core\src\Bridge\Doctrine\Orm\SubresourceDataProvider.php",
"line": 139,
"args": []
},
{
"namespace": "ApiPlatform\Core\Bridge\Doctrine\Orm",
"short_class": "SubresourceDataProvider",
"class": "ApiPlatform\Core\Bridge\Doctrine\Orm\SubresourceDataProvider",
"type": "->",
"function": "buildQuery",
"file": "my-project\symfony\vendor\api-platform\core\src\Bridge\Doctrine\Orm\SubresourceDataProvider.php",
"line": 94,
"args": [
[
"array",
{
"id": [
"array",
{
"id": [
"integer",
5548
]
}
]
}
],
[
"array",
{
"property": [
"string",
"civilite"
],
"identifiers": [
"array",
[
[
"array",
[
[
"string",
"id"
],
[
"string",
"App\Api\EndPoint\Patients\ByUser"
],
[
"boolean",
true
]
]
]
]
],
"collection": [
"boolean",
false
],
"operationId": [
"string",
"api_patients by users_civilite_get_subresource"
],
"groups": [
"array",
[
[
"string",
"civilite:read"
]
]
],
"operation_type": [
"string",
"subresource"
],
"subresource_operation_name": [
"string",
"api_patients by users_civilite_get_subresource"
],
"resource_class": [
"string",
"Entity\Civilite"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/patients/by_user/5548/civilite"
],
"uri": [
"string",
"http://localhost:81/api/patients/by_user/5548/civilite"
],
"subresource_identifiers": [
"array",
{
"id": [
"string",
"5548"
]
}
],
"subresource_resources": [
"array",
{
"App\Api\EndPoint\Patients\ByUser": [
"array",
{
"id": [
"string",
"5548"
]
}
]
}
],
"has_identifier_converter": [
"boolean",
true
]
}
],
[
"object",
"ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator"
],
[
"object",
"Doctrine\ORM\QueryBuilder"
],
[
"string",
"o"
],
[
"integer",
1
]
]
},
{
"namespace": "ApiPlatform\Core\Bridge\Doctrine\Orm",
"short_class": "SubresourceDataProvider",
"class": "ApiPlatform\Core\Bridge\Doctrine\Orm\SubresourceDataProvider",
"type": "->",
"function": "getSubresource",
"file": "my-project\symfony\vendor\api-platform\core\src\Bridge\Symfony\Bundle\DataProvider\TraceableChainSubresourceDataProvider.php",
"line": 63,
"args": [
[
"string",
"Entity\Civilite"
],
[
"array",
{
"id": [
"array",
{
"id": [
"integer",
5548
]
}
]
}
],
[
"array",
{
"property": [
"string",
"civilite"
],
"identifiers": [
"array",
[
[
"array",
[
[
"string",
"id"
],
[
"string",
"App\Api\EndPoint\Patients\ByUser"
],
[
"boolean",
true
]
]
]
]
],
"collection": [
"boolean",
false
],
"operationId": [
"string",
"api_patients by users_civilite_get_subresource"
],
"groups": [
"array",
[
[
"string",
"civilite:read"
]
]
],
"operation_type": [
"string",
"subresource"
],
"subresource_operation_name": [
"string",
"api_patients by users_civilite_get_subresource"
],
"resource_class": [
"string",
"Entity\Civilite"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/patients/by_user/5548/civilite"
],
"uri": [
"string",
"http://localhost:81/api/patients/by_user/5548/civilite"
],
"subresource_identifiers": [
"array",
{
"id": [
"string",
"5548"
]
}
],
"subresource_resources": [
"array",
{
"App\Api\EndPoint\Patients\ByUser": [
"array",
{
"id": [
"string",
"5548"
]
}
]
}
],
"has_identifier_converter": [
"boolean",
true
]
}
],
[
"string",
"api_patients by users_civilite_get_subresource"
]
]
},
{
"namespace": "ApiPlatform\Core\Bridge\Symfony\Bundle\DataProvider",
"short_class": "TraceableChainSubresourceDataProvider",
"class": "ApiPlatform\Core\Bridge\Symfony\Bundle\DataProvider\TraceableChainSubresourceDataProvider",
"type": "->",
"function": "getSubresource",
"file": "my-project\symfony\vendor\api-platform\core\src\DataProvider\OperationDataProviderTrait.php",
"line": 78,
"args": [
[
"string",
"Entity\Civilite"
],
[
"array",
{
"id": [
"array",
{
"id": [
"integer",
5548
]
}
]
}
],
[
"array",
{
"property": [
"string",
"civilite"
],
"identifiers": [
"array",
[
[
"array",
[
[
"string",
"id"
],
[
"string",
"App\Api\EndPoint\Patients\ByUser"
],
[
"boolean",
true
]
]
]
]
],
"collection": [
"boolean",
false
],
"operationId": [
"string",
"api_patients by users_civilite_get_subresource"
],
"groups": [
"array",
[
[
"string",
"civilite:read"
]
]
],
"operation_type": [
"string",
"subresource"
],
"subresource_operation_name": [
"string",
"api_patients by users_civilite_get_subresource"
],
"resource_class": [
"string",
"Entity\Civilite"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/patients/by_user/5548/civilite"
],
"uri": [
"string",
"http://localhost:81/api/patients/by_user/5548/civilite"
],
"subresource_identifiers": [
"array",
{
"id": [
"string",
"5548"
]
}
],
"subresource_resources": [
"array",
{
"App\Api\EndPoint\Patients\ByUser": [
"array",
{
"id": [
"string",
"5548"
]
}
]
}
],
"has_identifier_converter": [
"boolean",
true
]
}
],
[
"string",
"api_patients by users_civilite_get_subresource"
]
]
},
{
"namespace": "ApiPlatform\Core\EventListener",
"short_class": "ReadListener",
"class": "ApiPlatform\Core\EventListener\ReadListener",
"type": "->",
"function": "getSubresourceData",
"file": "my-project\symfony\vendor\api-platform\core\src\EventListener\ReadListener.php",
"line": 100,
"args": [
[
"array",
{
"id": [
"array",
{
"id": [
"integer",
5548
]
}
]
}
],
[
"array",
{
"resource_class": [
"string",
"Entity\Civilite"
],
"subresource_context": [
"array",
{
"property": [
"string",
"civilite"
],
"identifiers": [
"array",
[
[
"array",
[
[
"string",
"id"
],
[
"string",
"App\Api\EndPoint\Patients\ByUser"
],
[
"boolean",
true
]
]
]
]
],
"collection": [
"boolean",
false
],
"operationId": [
"string",
"api_patients by users_civilite_get_subresource"
]
}
],
"subresource_operation_name": [
"string",
"api_patients by users_civilite_get_subresource"
],
"receive": [
"boolean",
true
],
"persist": [
"boolean",
true
]
}
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"civilite:read"
]
]
],
"operation_type": [
"string",
"subresource"
],
"subresource_operation_name": [
"string",
"api_patients by users_civilite_get_subresource"
],
"resource_class": [
"string",
"Entity\Civilite"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/api/patients/by_user/5548/civilite"
],
"uri": [
"string",
"http://localhost:81/api/patients/by_user/5548/civilite"
],
"subresource_identifiers": [
"array",
{
"id": [
"string",
"5548"
]
}
],
"subresource_resources": [
"array",
{
"App\Api\EndPoint\Patients\ByUser": [
"array",
{
"id": [
"string",
"5548"
]
}
]
}
],
"has_identifier_converter": [
"boolean",
true
]
}
]
]
},
{
"namespace": "ApiPlatform\Core\EventListener",
"short_class": "ReadListener",
"class": "ApiPlatform\Core\EventListener\ReadListener",
"type": "->",
"function": "onKernelRequest",
"file": "my-project\symfony\vendor\symfony\event-dispatcher\Debug\WrappedListener.php",
"line": 111,
"args": [
[
"object",
"Symfony\Component\HttpKernel\Event\GetResponseEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher\Debug",
"short_class": "WrappedListener",
"class": "Symfony\Component\EventDispatcher\Debug\WrappedListener",
"type": "->",
"function": "__invoke",
"file": "my-project\symfony\vendor\symfony\event-dispatcher\EventDispatcher.php",
"line": 212,
"args": [
[
"object",
"Symfony\Component\HttpKernel\Event\GetResponseEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\Component\EventDispatcher\EventDispatcher"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\Component\EventDispatcher\EventDispatcher",
"type": "->",
"function": "doDispatch",
"file": "my-project\symfony\vendor\symfony\event-dispatcher\EventDispatcher.php",
"line": 44,
"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"
],
[
"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.request"
],
[
"object",
"Symfony\Component\HttpKernel\Event\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\Component\EventDispatcher\EventDispatcher",
"type": "->",
"function": "dispatch",
"file": "my-project\symfony\vendor\symfony\event-dispatcher\Debug\TraceableEventDispatcher.php",
"line": 145,
"args": [
[
"string",
"kernel.request"
],
[
"object",
"Symfony\Component\HttpKernel\Event\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\Component\EventDispatcher\Debug",
"short_class": "TraceableEventDispatcher",
"class": "Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher",
"type": "->",
"function": "dispatch",
"file": "my-project\symfony\vendor\symfony\http-kernel\HttpKernel.php",
"line": 126,
"args": [
[
"string",
"kernel.request"
],
[
"object",
"Symfony\Component\HttpKernel\Event\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\Component\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\Component\HttpKernel\HttpKernel",
"type": "->",
"function": "handleRaw",
"file": "my-project\symfony\vendor\symfony\http-kernel\HttpKernel.php",
"line": 67,
"args": [
[
"object",
"Symfony\Component\HttpFoundation\Request"
],
[
"integer",
1
]
]
},
{
"namespace": "Symfony\Component\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\Component\HttpKernel\HttpKernel",
"type": "->",
"function": "handle",
"file": "my-project\symfony\vendor\symfony\http-kernel\Kernel.php",
"line": 198,
"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": "my-project\symfony\public\index.php",
"line": 37,
"args": [
[
"object",
"Symfony\Component\HttpFoundation\Request"
]
]
}
]
}

question

Most helpful comment

Because your resource is not a doctrine-managed entity you should do a data provider for it.

>All comments

Because your resource is not a doctrine-managed entity you should do a data provider for it.

Was this page helpful?
0 / 5 - 0 ratings