Caching error with Local Tasks on Media entities

Created on 21 April 2025, 3 days ago

Problem/Motivation

After upgrading our site from Drupal 9 to Drupal 10.4.5, a user reported the 'Edit' tab would randomly disappear from pages for media entities they had created. Clearing caches brings back the Edit tab, but over time it disappears again.

I found a way to reproduce this reliably on our Drupal 10 site. I can also reproduce the problem on simplytest.me, steps below. If I follow those steps on the backup D9 version of our site the bug doesn't happen, so it seems to have been introduced in D10.

I don't see any issue that exactly matches this problem, though there are several mentions of random caching errors with local tasks on this page: https://www.drupal.org/forum/support/module-development-and-code-questio...

Steps to reproduce

1. Go to https://simplytest.me/
2. Select Drupal Core 10.4.6, and click Launch Sandbox
3. Once the site is created, login as admin
4. Install the media module (Extend, select the media module, Install)
5. Configure media and enable access to individual images (Configuration > Media settings, tick ‘Standalone media URL’, ‘Save configuration’.)
6. Create two users, user1 and user2
7. Go to People > Permissions, and grant ‘Image: Create new media’ and ‘Image: Edit own media’ to ‘Authenticated user’
8. Log out and log in as user1
9. Browse to /media/add/image, upload an image, fill in Alternative text, and Save
10. The page /media/1 is displayed, showing View and Edit tabs
11. Log out and log in as user2
12. Browse to /media/1, no View or Edit tabs are shown, which is correct
13. Log out and log in as user1
14. Browse to /media/1, no View or Edit tabs are shown, which is the bug
15. Log out and log in as admin
16. Clear the caches (Configure > Performance > Clear all caches)
17. Log out and log in as user1
18. Browse to /media/1, and the View and Edit tabs are shown correctly again
19. If you repeat steps 11-14 the bug is reproduced again

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

10.4

Component

media system

Created by

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

Comments & Activities

  • Issue created by @davidhk
  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies .

  • If I look at the cache entries created in cache_render for the local tasks block on the media entity's page, the format of the Cache ID (cid) changes between D9 and D10 for user2, which may be a clue.

    On the D9 version of our site, the cid for both users' cache entries follows the same format:

    user1: cid=entity_view:block:gwulo_bartik_local_tasks:[languages:language_interface]=en:[route]=entity.media.canonical34c740ab870626d71720c57080a0e2f51a312008736b4ff30c26f559b09248c9:[theme]=gwulo_bartik:[user]=333486

    user2: cid=entity_view:block:gwulo_bartik_local_tasks:[languages:language_interface]=en:[route]=entity.media.canonical34c740ab870626d71720c57080a0e2f51a312008736b4ff30c26f559b09248c9:[theme]=gwulo_bartik:[user]=345

    On the D10 version of our site, the cid created when user1, the creator of the media entity, visits that entity's page is the same as it was on D9, but for user2 it now ends with [user.permissions]= instead of [user]=

    user1: cid=entity_view:block:gwulo_bartik_local_tasks:[languages:language_interface]=en:[route]=entity.media.canonical34c740ab870626d71720c57080a0e2f51a312008736b4ff30c26f559b09248c9:[theme]=gwulo_bartik:[user]=333486

    user2: cid=entity_view:block:gwulo_bartik_local_tasks:[languages:language_interface]=en:[route]=entity.media.canonical34c740ab870626d71720c57080a0e2f51a312008736b4ff30c26f559b09248c9:[theme]=gwulo_bartik:[user.permissions]=aZUlEhtP7-L6slUFK8dbCULl3Dpcui86eEIY_gCUy_E

    Disclaimer: These are copied from our full site which has custom code, but I can't think of any changes made during the D9-D10 upgrade that would cause the differences in cid shown above.

Production build 0.71.5 2024