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&nbsp;</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.

Comments

killua99 created an issue. See original summary.

killua99’s picture

I'd to revert to this point.

http://cgit.drupalcode.org/jsonapi/commit/?id=9bda831174466bf6a60fca0c5b...

Then the module start working again.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new1.34 KB

I've ran into things being NULL just way too often recently as well. The entire Drupal core base is full of those potential problems.

e0ipso’s picture

This 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.

dawehner’s picture

This looks like the way to go. It makes me wish to have EntityNull objects off of the entity reference...

I 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 __call and __get and throw a nicer exception instead.

e0ipso’s picture

Merging if green.

  • e0ipso committed fdcfbfe on 8.x-1.x
    fix(Serialization) Invalid interface passed to EntityCollection (#...
e0ipso’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

hedeshy’s picture

StatusFileSize
new976 bytes

Hi,

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.

sin’s picture

Category: Support request » Bug report

I 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!

dravenk’s picture

StatusFileSize
new588 bytes

Adapt to the latest 1.x code