Using [view:url] token throws a LogicException

Created on 22 August 2023, 10 months ago
Updated 24 August 2023, 10 months ago

Problem/Motivation

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. Returned object class: Drupal\Core\Cache\CacheableResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 154 of /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php).

Steps to reproduce

I was using Views Data Export , but this should also be reproduceable in core alone if you use the token.

  1. Create a view
  2. Add a "data export" display, with export to CSV
  3. Use the [view:url] token in the filename
  4. Save the view
  5. View the view and click to export to CSV
  6. The exception is thrown

Proposed resolution

Replace

              $replacements[$original] = $url->setOptions($url_options)
                ->toString();

with

              $replacements[$original] = $url->setOptions($url_options)
                ->toString(TRUE)->getGeneratedUrl();

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated 1 minute ago

Created by

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

Comments & Activities

Production build 0.69.0 2024