filefield_paths_process_string() which handles file's name & path to transformations makes use of token replacement.

In some case, token replacement leads to triggering some rendering. When this occurs in a "non-webpage" context, such as JSON:API or REST requests, this rendering create caching metadata which bubble up and is never catched/handled, leading to one of the most absconse/undebuggable error of a D8 project right now : the dreaded

"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"

I think filefield_paths_process_string() must wrap its logic in a render context to catch the generated metadata and handle it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

garphy created an issue. See original summary.

garphy’s picture

Here's a quick attempt to wrap the logic in a separate RenderContext and pop the generated metadata just before returning the result.

garphy’s picture

Status: Closed (duplicate) » Needs review
stefan.butura’s picture

Worked fine for me. Thank you so much.