Problem/Motivation

#2984964-12: JSON API + hook_node_grants() implementations: accessing /jsonapi/node/article as non-admin user results in a cacheability metadata leak caused me to look at consumer_image_styles, which led me to \Drupal\consumer_image_styles\Normalizer\ImageEntityNormalizer::buildVariantValues().

There are at least two cacheability bugs there:

  1. It's not catching bubbled cacheability from building the file URL. (This is what #2984964-12: JSON API + hook_node_grants() implementations: accessing /jsonapi/node/article as non-admin user results in a cacheability metadata leak reported.)
  2. It's not adding the cacheability for the used image styles.

Proposed resolution

Fix both.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#2 2985403-2.patch1.37 KBwim leers

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.37 KB

This fixes point 2.

Point 1 still needs to be fixed. Tests are also missing.

wim leers’s picture

madeltoro’s picture

Thanks you alot. This issue goes to make me crazy!!! Just in time :)

pwolanin’s picture

Thanks Wim - will test it out.

pwolanin’s picture

This patch didn't fix the error I'm seeing, so might be another place (or another in addition).

[Fri Jul 13 11:59:12 2018] Uncaught PHP Exception 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\jsonapi\ResourceResponse. Array
(
    [#cache] => Array
        (
            [contexts] => Array
                (
                    [0] => url.site
                )

            [tags] => Array
                (
                )

            [max-age] => -1
        )

    [#attached] => Array
        (
        )

)
wim leers’s picture

This patch didn't fix the error I'm seeing, so might be another place (or another in addition).

That's point 1 in the IS, which #2 says it did not yet fix.

e0ipso’s picture

Status: Needs review » Needs work

Thanks @Wim Leers! The patch looks great so far. Hopefully we can get completion on the rest of the issue as described in #2 and highlighted on #6.

littletiger’s picture

Hi all, not sure what the meaning is of catching bubbled cacheability.
So the bug or issue I experienced just now might or might not be related.

JSONAPI output didn't show any meta.derivatives, where there should be some. Neither in the browser nor in my angular front-end app.
In the browser, as the documentation says, I then added _consumer_id=... . I had to refresh the cache, then the meta.derivatives showed up.
If I then remove the _consumer_id=... and clear the cache again, the meta.derivatives are still there.

So I'm confused. One part seems to be caching acting a bit weirdly, or in a way i don't understand :)
The other part is... do I need to somehow supply the consumer id as a url parameter with all requests, despite already using it with /oauth/token? (This is a separate question... so feel free to ignore that :)

dremy’s picture

I am seeing the same issue as "#2927782: Some derivatives are randomly missing" - where all derivatives just disappeared after a "drush cache-rebuild"

So I attempted to apply the patch "2985403-2.patch" but it fails on Drupal 8.6.2 and consumer_image_styles 8.x-2.0-rc6

patching file src/Normalizer/ImageEntityNormalizer.php
Hunk #1 FAILED at 132.
1 out of 1 hunk FAILED -- saving rejects to file src/Normalizer/ImageEntityNormalizer.php.rej

pieterdt’s picture

I'm having the same problem: testing 50 nodes of a single content type, all have the image field filled in. 20 of of 50 will not return derivatives when queried with jsonapi/consumer_image_styles.
They will return the regular image field info about the image file, but no derivatives (hence I know for sure they image is attached).

A cache rebuild didn't improve the result, however, saving the node again, did help. After saving (tried with one) it, the imageDerivatives were set correctly. Maybe this gives a hint in where to fix this.

e0ipso’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
Status: Needs work » Fixed

Closing. Hopefully we can focus on 8.x-3.x instead.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.