Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293828

Catch EarlyRendering Exception for REST-Resources

$
0
0

Problem/Motivation

There are some issue where people always have the same issue running in a LogicException "The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early" when extending ResourceBase.

See #3052553: Entity query alter with cacheable metadata leaks and triggers LogicException, #2876258: No sane way to pass Access Cacheability of EntityQuery. #2638686: Exception in EarlyRenderingControllerWrapperSubscriber is a DX nightmare, remove it

Specially in #2638686: Exception in EarlyRenderingControllerWrapperSubscriber is a DX nightmare, remove it starting from comment 17 there are people discussing a lot of workarounds for different situations.

These are so far:

  • Creating links
  • Using serializer
  • Doing a query which is altered, which creates a cache tag (see node_query_node_access_alter)

Proposed resolution

If a query alter happens (node_query_node_access_alter) then the correct solution would be #3028976: Enable an entity query's return value to carry cacheability.

For the other cases there is currently no other issue I'm aware of.

So my proposed solution would be that the RequestHandler executes the controller inside a context and add the cache metadata from there to the response. This would help a lot of developers not running into this issue and would relate to CR https://www.drupal.org/node/2513810 to not have to do this "workaround" so much.

Remaining tasks

  • Review patch
  • Discuss proposed resolution

User interface changes

none.

API changes

Bubble metadata inside REST requests will now automaticcly attached to the response.

Data model changes

none.

Release notes snippet


Viewing all articles
Browse latest Browse all 293828

Trending Articles