I'm having an Error 500 on POST requests, something related about an EntityInterface.
The error on the server is.
TypeError: Argument 1 passed to Drupal\Core\Entity\EntityRepository::getTranslationFromContext() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /www/conventus/docroot/web/modules/contrib/jsonapi/src/Normalizer/EntityReferenceFieldNormalizer.php on line 92 in Drupal\Core\Entity\EntityRepository->getTranslationFromContext() (line 82 of /www/conventus/docroot/web/core/lib/Drupal/Core/Entity/EntityRepository.php)
The request is a POST to /jsonapi/node/article?_format=api_json
The body:
{
"data": {
"type": "node--article",
"id": "d9ad5222-c502-46fb-ace4-7d510cb9960a",
"attributes": {
"uuid": "d9ad5222-c502-46fb-ace4-7d510cb9960a",
"langcode": "sv",
"title": "Asdasd asdasd asdad",
"status": 0,
"created": 1485872587,
"changed": 1485872626,
"promote": 0,
"sticky": 0,
"revision_timestamp": 1485872626,
"revision_log": null,
"revision_translation_affected": null,
"default_langcode": true,
"path": {
"alias": "",
"pid": null
},
"body": {
"value": "<p>ASdasd asdasdas asdasd asdasdas dasdasd asdasda sda sdas </p>\r\n",
"format": "editor_mode",
"summary": ""
},
"field_extra_title": "ASdasd",
"field_feature_place": "9",
"field_ingress": {
"value": "<p>Asdasdads asdasd asdasdasd asdasdasd</p>\r\n",
"format": "editor_mode"
},
"field_teaser": "ASdasd",
"field_tt_job": null,
"own_publish": 1
},
"relationships": {
"uid": {
"data": [
{
"type": "user--user",
"id": "62d1f7fd-b871-4c6c-9873-58995d70f76e"
}
]
},
"revision_uid": {
"data": [
{
"type": "user--user",
"id": "62d1f7fd-b871-4c6c-9873-58995d70f76e"
}
]
}
}
}
}I'm trying to debug to find where is my error. If someone have some advice about it, please shoot.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | skip-entity-null_2848419_12.patch | 588 bytes | dravenk |
| #10 | skip-entity-null_2848419_10.patch | 976 bytes | hedeshy |
| #6 | 2848419--null-entities-error--6.patch | 1.29 KB | e0ipso |
| #6 | 2848419--interdiff--3-6.txt | 1.51 KB | e0ipso |
| #3 | 2848419-3.patch | 1.34 KB | dawehner |
Comments
Comment #2
killua99 commentedI'd to revert to this point.
http://cgit.drupalcode.org/jsonapi/commit/?id=9bda831174466bf6a60fca0c5b...
Then the module start working again.
Comment #3
dawehnerI've ran into things being NULL just way too often recently as well. The entire Drupal core base is full of those potential problems.
Comment #4
e0ipsoThis looks like the way to go. It makes me wish to have EntityNull objects off of the entity reference...
I'll give this a proper look when I'm on my laptop.
Comment #5
dawehnerI was thinking about that for a while and I said, nope, this won't be super useful. Null objects work fine when you have a limited domain, aka. value objects, where you know what will happen. An entity though contains so many possible things, rather infinite amount of them, you end up with an object potentially which doesn't behave like the entity you expect to return.
On the other hand it could implement
__calland__getand throw a nicer exception instead.Comment #6
e0ipsoMerging if green.
Comment #8
e0ipsoComment #10
hedeshy commentedHi,
I have found this problem after updating to the latest version of JSONAPI. The problem is that when using paragraphs, a layout can have no paragraph or any content inside. Therefore, the entity reference field can be actually null.
I think simply skipping if there is no entity is better than 500 error.
Comment #11
sin commentedI found this error in JSON API 1.23 while doing GET for jsonapi/commerce_order.
It worked fine with JSON API 1.16, so marking as a bug, please reopen.
The patch #10 fixes it, thanks!
Comment #12
dravenkAdapt to the latest 1.x code