"LogicException: The controller result claims to be providing relevant cache metadata..." error

Created on 16 May 2023, over 1 year ago
Updated 26 February 2024, 10 months ago

Problem/Motivation

There is an error after the module was installed:
"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

1. Install the module
2. Do request like /jsonapi/my_entity/my_entity/5df4c3c9-82bd-4536-9430-cba192547f5c/images

Drupal 10.0.9

πŸ› Bug report
Status

Postponed: needs info

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @goodboy
  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine
  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States wells Seattle, WA

    @goodboy -- I'm not able to reproduce this error. Could you provide reproduction steps that start from a clean install of just Drupal 10 and this module? Otherwise more detailed information about the configuration where you are having this issue or a complete backtrace of the error would be helpful.

  • πŸ‡©πŸ‡ͺGermany ro-no-lo

    I had this also. The thing is this: When I upload IMAGES: via the JSON:API process described here: https://www.drupal.org/node/3024331 β†’ it seems that the jsonapi_image_style module creates a `CachableResponse`. which will throw an exception in the file:

    File: EarlyRenderingControllerWrapperSubscriber.php

          // If a non-Ajax Response or domain object is returned and it cares about
          // attachments or cacheability, then throw an exception: early rendering
          // is not permitted in that case. It is the developer's responsibility
          // to not use early rendering.
          elseif ($response instanceof AttachmentsInterface || $response instanceof CacheableResponseInterface || $response instanceof CacheableDependencyInterface) {
            throw new \LogicException(sprintf('The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Ensure you are not rendering content too early. Returned object class: %s.', get_class($response)));
          }
          else {
            // A Response or domain object is returned that does not care about
            // attachments nor cacheability; for instance, a RedirectResponse. It is
            // safe to discard any early rendering metadata.
          }
        }
    

    As info: I have an entity where uploading any type of files is okay. When I upload a Image the error occurs and the CachableResponse has a content of:

    {"jsonapi":{"version":"1.0","meta":{}},"data":[{"type":"file--file","id":"c4837397-5e48-41d6-9002-60f68d0e02f5","attributes":{"drupal_internal__fid":721,"langcode":"en","filename":"13.jpeg","uri":{"value":"private:\/\/2024-02\/13_1.jpeg","url":"\/system\/files\/2024-02\/13_1.jpeg?token=nOrLl1pNJflU-H2bVCtDthM6moemK64Q9MDQaN6PRCc&timestamp=1708955605"},"filemime":"image\/jpeg","filesize":8020217,"status":true,"created":"2024-02-26T13:53:25+00:00","changed":"2024-02-26T13:53:25+00:00","image_style_uri":{"avatar":"http:\/\/foobar.local\/system\/files\/styles\/avatar\/private\/2024-02\/13_1.jpeg?token=Rt1fiI8d14VxngMdOnP9r745AXDBhH6VaTcFFckMzIs&timestamp=1708955605&itok=LM9rqf7H","max_650x650":"http:\/\/foobar.local\/system\/files\/styles\/max_650x650\/private\/2024-02\/13_1.jpeg?token=tNO_kBMwcuLRAjt2I9pUX05glzRjdCmK88dC6QVKOhQ&timestamp=1708955605&itok=QYcmOtOQ","thumbnail":"http:\/\/foobar.local\/system\/files\/styles\/thumbnail\/private\/2024-02\/13_1.jpeg?token=l4ViEWtsOLHCRn1G8b3v7NZGhBzZXoPwm_jfys1-OlY&timestamp=1708955605&itok=Oypb40X-","usericon":"http:\/\/foobar.local\/system\/files\/styles\/usericon\/private\/2024-02\/13_1.jpeg?token=szA6cAFC67hB-vPw9zZMvdkhWiX5e4xRBW4DxajFJk0&timestamp=1708955605&itok=SIMJP2lO"}},"relationships":{"uid":{"data":{"type":"user--user","id":"cfecacbc-701e-4bb6-83e3-2a8b15a83fbe","meta":{"drupal_internal__target_id":32}}}}}]}
    

    At least for me, this happens. Uploading 1 or more PDF. No problem. Uploading JPGs: Exception.

  • πŸ‡©πŸ‡ͺGermany ro-no-lo

    I checked: when jsonapi_image_styles is uninstalled it works as expected.

    I digged a bit deeper.

    The ImageStyleNormalizedFieldItemList::computeValue is called in the Validationphase of the FileUpload call, which I don't understand, because, what exactly are you validating there? No idea. Anyways and the same method is called in the serializition Phase, which makes more sense. The thing is even with stepping through the process, I do not understand why it fails, because jsonapi is supposed to anser an fileupload with a json string of the newly created file--file objects.

    It bothers me even more, that the upload of the image and the attachment to the entity with the reference seem to work perfectly. Only an EarlyRendererWrapperSomething is bothered and throws an exception. :-(

Production build 0.71.5 2024