• Resolved korynorthrop

    (@korynorthrop)


    I have been making use of getEntityRecords() to fetch image data to display in some custom Gutenberg blocks. They worked fine until I upgraded to WordPress 5.6. However, I can successfully fetch image data by using getMedia(). This was the behavior I experienced on my live and staging sites. I deactivated all plugins and re-activated them one by one and determined that WP REST Cache was causing the conflict.

    Steps to reproduce the behavior:

    1. Make a clean WordPress installation
    2. Upload an image to the media library and take note of it’s post_id (let’s say it’s 6)
    3. Open the page editor and the Javascript console then type in wp.data.select('core').getEntityRecords('postType', 'attachment', { include: [ 6 ] })
    4. You’ll see null returned, which is normal since the image is still being fetched, but repeating the getEntityRecords call after a few seconds should return an array with the media item details
    5. Instead type in wp.data.select(‘core’).getMedia(6) (same as above, you’ll likely get ‘undefined’ the first time while it’s fetching the media item, but if you re-enter you should be able to see the details for that image)

    I tried clearing the WP REST cache while testing, thinking that would alleviate any potential conflicts with these getEntityRecords() calls, but clearing the cache had no effect I consistently received null responses on the getEntityRecords calls. Whenever I disable WP REST Cache everything works as expected.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @korynorthrop

    Thank you for using our plugin!

    I have tried to reproduce your issue, but unfortunately I was unable to reproduce it. I have installed a clean WordPress 5.6 site and installed the latest version of our plugin. Next I followed your steps to reproduce the issue, and indeed at first I get a null returned for step 4 but after a few tries I get the array with media item details. After that I did step 5 and again at first I get undefined the first time, but after another try I get the details for the image.

    Are you sure you are using the latest version of our plugin? The endpoints are being called using a nonce and as of version 2020.2.0 of our plugin calls with a nonce are ignored and not cached. So in newer versions these calls should not give you any trouble. However even if you were using an earlier version you shouldn’t have any issues since we don’t cache the results if the results are empty. I even tried to reproduce the issue with version 2020.1.1 of our plugin, but also then I did not encounter the same issue.

    So unfortunately at this point I am unable to solve the issue as I am unable to reproduce it. Can you tell me if you indeed used a completely clean install of WordPress? So with the default Twenty Twenty-One theme enabled and other than our plugin no other plugins enabled? And on what server configuration are you hosting this site, maybe it has something to do with this configuration?

    Thread Starter korynorthrop

    (@korynorthrop)

    Thanks for your reply. I created a brand new sandbox and only installed WP REST Cache then repeated the process I outlined above. This time everything worked fine, just like your testing showed. So, I’m not sure what happened with my first new install.

    Anyway, I re-examined by production and staging sites, disabling all plugins and switching to Twentytwentyone theme. Everything worked fine with just WP REST Cache enabled. I re-enabled the remaining plugins one-by-one and re-tested and I found that there might be some kind of conflict between WP REST Cache and the PublishPress Revisions Pro plugin. A NULL value is consistently returned if both plugins are active at the same time, however if I only have one enabled (doesn’t matter which one) then the
    wp.data.select('core').getEntityRecords('postType', 'attachment', { include: [ 6 ] })
    call returns the media data properly.

    Any thoughts on how to dig further into this? I can raise a ticket with the author of PublishPress Revisions Pro as well, just curious if any potential thoughts come to mind on what could possibly be conflicting.

    • This reply was modified 3 years, 11 months ago by korynorthrop.
    Plugin Author Richard Korthuis

    (@rockfire)

    Hi @korynorthrop

    I did some debugging with the PublishPress Revisions plugin. Since I don’t have the Pro version, I tested with the free version which had the same issue. And I did find the issue!

    In their plugin in the file rvy_init.php in the function my_post_types_config() if our plugin is active, they overwrite the REST Controller Class for all post types with WP_REST_Posts_Controller, so also for the attachments. This is incorrect for the attachment post type it should be WP_REST_Attachments_Controller. This is something they should fix and isn’t something I can create a fix for in our plugin.
    N.B. I am curious as to why they overwrite this REST Controller Class, so if they happen to let you know, please share it. Maybe there is something we can do in our plugin to make that step unnecessary.

    @rockfire @korynorthrop

    This was due to some diagnostic / development code which I accidentally left active. It’s removed in the following beta version. I’m on my way out now, but will get this into www.ads-software.com svn as the Development Version later today.

    https://github.com/publishpress/PublishPress-Revisions/releases/tag/v2.4.9-rc

    @rockfire @korynorthrop PublishPress Revisions 2.4.9-rc is now available through www.ads-software.com as the “Development Version”

    https://downloads.www.ads-software.com/plugin/revisionary.zip

    @korynorthrop If you’d like a copy of Revisions Pro 2.4.9-rc, just create a help ticket on publishpress.com

    Thread Starter korynorthrop

    (@korynorthrop)

    Thank you very much @rockfire for chasing down the problematic code in the Revisions plugin and thank @kevinb for making the appropriate fix so promptly. I have been out of the office all week and am just seeing this now. I’ll be sure to open a ticket to get the 2.4.9-rc version. Happy new year, y’all.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WP REST Cache conflicts with getEntityRecords() calls for ‘attachme’ is closed to new replies.