I'm facing a problem using Api-platform:2.7. Everything works fine in my application with PHP Attributes and APi resources. However, I find out that when I composer require doctrine/mongodb-odm-bundle
, all the POST resources become unusable. my application is using both an SQL and a Mongo database.
Removing the composer package fix the error.
This is the doctrine_mongodb.yaml I'm using (I tried with and without the auto_mapping. Same error)
doctrine_mongodb:
auto_generate_proxy_classes: true
auto_generate_hydrator_classes: true
connections:
default:
server: '%env(resolve:MONGODB_URL)%'
options: {}
default_database: '%env(resolve:MONGODB_DB)%'
document_managers:
default:
# auto_mapping: true
mappings:
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Document'
prefix: 'App\Document'
alias: App
Here is the error stacktrace:
{
"@context": "/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "Unable to generate an IRI for the item of type \"App\\Entity\\TryingResource\"",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/srv/api/vendor/api-platform/core/src/Symfony/Routing/IriConverter.php",
"line": 177,
"args": []
},
{
"namespace": "ApiPlatform\\Symfony\\Routing",
"short_class": "IriConverter",
"class": "ApiPlatform\\Symfony\\Routing\\IriConverter",
"type": "->",
"function": "getIriFromResource",
"file": "/srv/api/vendor/api-platform/core/src/Symfony/EventListener/WriteListener.php",
"line": 113,
"args": [
[
"object",
"App\\Entity\\TryingResource"
]
]
},
{
"namespace": "ApiPlatform\\Symfony\\EventListener",
"short_class": "WriteListener",
"class": "ApiPlatform\\Symfony\\EventListener\\WriteListener",
"type": "->",
"function": "onKernelView",
"file": "/srv/api/vendor/symfony/event-dispatcher/Debug/WrappedListener.php",
"line": 117,
"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/api/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 230,
"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": "callListeners",
"file": "/srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 59,
"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"
]
]
],
[
"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/api/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php",
"line": 154,
"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/api/vendor/symfony/http-kernel/HttpKernel.php",
"line": 158,
"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/api/vendor/symfony/http-kernel/HttpKernel.php",
"line": 75,
"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/api/vendor/symfony/http-kernel/Kernel.php",
"line": 202,
"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/api/public/index.php",
"line": 28,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
]
]
}
]
}
The problem came from a bug in api-platform and it was not able to work with both ORM and ODM.
It relates to this issue : https://github.com/api-platform/core/issues/5020
Fix was made in this PR : https://github.com/api-platform/core/pull/5032