Catch EarlyRendering Exception for REST-Resources

Created on 11 September 2019, about 5 years ago
Updated 27 September 2024, about 2 months ago

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: Add a way to pass Access Cacheability of EntityQuery β†’ . πŸ“Œ Exception in EarlyRenderingControllerWrapperSubscriber is a DX nightmare, remove it Needs work

Specially in πŸ“Œ Exception in EarlyRenderingControllerWrapperSubscriber is a DX nightmare, remove it Needs work 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 adds a cache context (see node_query_node_access_alter)

Proposed resolution

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

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

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
RenderΒ  β†’

Last updated 2 days ago

Created by

πŸ‡©πŸ‡ͺGermany kfritsche πŸ‡©πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024