1

I'm trying to create new nodes by POSTing to /entity/node?_format=json. This is the body I'm sending:

{
    "_links": {
        "type": {
            "href": "http:\/\/my.drupal.be\/rest\/type\/node\/group_of_documents"
        }
    },
    "title": [{
        "value": "Direct test - type 682"
    }],
    "body": [{
        "value": ""
    }],
    "field_owner": [{
        "value": "Symfony"
    }],
    "field_type": [{
        "target_id": "682"
    }]
}

And, in a way, this works. Because the document gets made, and everything is filled in.

But I keep getting an error:

A fatal error occurred:
The controller result claims to be providing relevant cache metadata,
but leaked metadata was detected.
Please ensure you are not rendering content too early.
Returned object class: Drupal\rest\ResourceResponse.

If I create a node without field_type, it doesn't throw an error.

field_type is the only field that has the Reference type -> Reference views -> Reference method set to Views: Filter by an entity reference view. Does that have anything to do with it?

2
  • same happened to me on REST GET when called Url::fromRoute('entity.node.canonical', ['node' => $node->id()], $options); $url->toString(); – Adi Jul 21 '16 at 15:56
  • Getting the same thing when using snippet similar to @Adi – Chris Rockwell Mar 25 '17 at 15:12
3

That's a core bug, see https://www.drupal.org/node/2626298 and https://www.drupal.org/node/2663638 (either of those two would avoid this).

The views reference thing is a good hint. Sounds something runs there that then triggers this exception. You could open an issue for that too if you can find the exact reason.

0

Try changing response to (maybe helps you) after you save node, because ResourceResponse is cachable...in this way we don't cache POST method.

return new ModifiedResourceResponse($node);

https://tutel.me/c/drupal/questions/249627/logicexception+node+save+via+resourcebase+post#

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.