Problem/Motivation
The local tasks (specifically the 'View' link) associated with an entity do not update immediately when its URL alias is modified. To reflect the changes, the Drupal cache must be cleared. Without clearing the cache, the 'View' link points to the old alias which results in "page not found" error.
Debugging showed that cache tags of an entity are not incuded in local tasks.
Steps to reproduce
- Install with standard profile
- create an aricle, Give URL alias and save.
- Edit the created article, Change the URL alias and save.
- No click on 'View' link from the local tasks.
- 'View' link leads to 404 as it is still using old alias.
- Clear Drupal cache and try again.
- 'View' link points to the new alias.

Taxonomy term also show similer behaviour
Proposed resolution
The cache tags associated with an entity should be linked to it's local task block.
Remaining tasks
None
User interface changes
NA
API changes
NA
Data model changes
NA
Release notes snippet
NA
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | 2927141-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #45 | 2927141-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-2927141
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
geertvd commentedDid some more research on this.
When checking the cache_render table I noticed that the local tasks block on the node edit route is receiving the node's cache tag (
node:1).This is not the case for the local tasks block on the term edit route.
This leads me to
LocalTasksBlock, we can see the block fetches it's cache tags from the local task manager service (LocalTaskManager).After some debugging I noticed that the node cache tag is being added in
LocalTaskManager::getTasksBuild():The above snippet is executed for all the local tasks within 1 local tasks block. For a local task block on nodes these are:
The node cache tag is only added because of the last local task (
entity.node.version_history), it is passed in the$accessparameter.Checking the access handler for the
entity.node.version_historyroute (NodeRevisionAccessCheck) shows that the node's cache tag is added in it's access-result:The other routes (for both node and taxonomy_term local tasks) use
EntityAccessControlHandler::access()for their access check which doesn't add the entity as a cacheable dependency.Comment #3
geertvd commentedJust working on some tests for this.
Comment #4
geertvd commentedTest + quick fix, this will probably break some other tests.
Comment #14
jeroentI followed the steps in the IS but was unable to reproduce this error.
Feel free to reopen if you still think this is a bug.
Comment #16
quietone commented@JeroenT, thanks for looking into this issue. I got different results.
I tested this on Drupal 10.0.x, standard install and using the steps in the Issue Summary I was able to reproduce the problem.
Clearing the cache fixes the problem. This now needs to be updated to 10.0.x, adding reroll tag and setting to NW.
Comment #17
ravi.shankar commentedAdded reroll of patch #4 on Drupal 10.0.x.
Comment #18
jeroentComment #19
detroz commentedI have the same problem with node and Sub-pathauto (Sub-path URL Aliases) : when the node's path is changed, the subpaths are always with the previous path and not the new one. For exemple, the local tasks links are wrong now. So, it's not very easily to edit or delete the node in that condition. Only a clear cache resolve that.
I updated the patch #4 to be compatible with Drupal 9.5.x (I didn't yet test it on Drupal 10).
Comment #20
akhil babuComment #21
akhil babuI tested this issue in Drupal 11 and it is still reproducible. Unlike #2, this issue was reproducible for nodes as well.
Comment #22
akhil babuHowever, this issue was not reproducible for any of the entities in the demo_umami profile. While debugging the cache tags in the standard profile, showed that the cache tags of the entity were not linked to the local task block, where the cache tag for the entity was correctly linked to the local task in the umami profile.
As @geertvd pointed out in #2, cache tags are added to the local tasks block through access checks. Currently,
EntityAccessControlHandler::access()does not add any cache tags associated with the entity to the access results. Therefore, the local task block won’t receive any cache tags related to the entity.In demo_umami profile, since content_moderation module is enabled, local task access checks eventually invoke
content_moderation_entity_accessand it adds the entity as a cachable dependency to the access result.Comment #24
akhil babuPatch #19 attempted to add a cachable dependency from the
EntityAccessControlHandler. But it resulted in numerous test failures.Link to the failed pipeline: https://git.drupalcode.org/issue/drupal-2927141/-/pipelines/82261
Exploring another option, we could integrate cache tags directly from the local tasks block, if the current route is related to an entity.
Comment #25
akhil babuComment #26
akhil babuComment #27
akhil babuThe new change caused only one test failure .
The test makes a field translatable and tries to add 'French' translation to it's label and help text.
Then it checks if the translation is saved or not.
The code uses
$this->clickLink('Add');the second time also to check the added translation which is wrong. If a translation is already added, then the link text should be 'Edit' instead of 'Add'.Without the fix in MR 6315, the link text would remain as 'Add,' which is a bug that was somehow overlooked. Correcting the test.
Comment #28
akhil babuThis needs tests. But temporarly moving to needs review for core maintainers to check the proposed solution and provide further guidance.
Comment #31
smustgrave commentedAppears to have a test failure.
Have not retested.
Comment #32
akhil babuWhen a node/taxonomy term is created with an alias like this
The ‘view’ link in its local task will have the link ‘/subdirectory/original-node-alias’ when the test is executed. This lead to the test failure.
I believe this issue arises because
SIMPLETEST_BASE_URLis set ashttp://localhost/subdirectoryin pipeline.ymlSo, to confirm that the link has been updated, I replaced
assertSame()withassertStringContainsString()in the test. Pipeline is up now.Comment #33
akhil babuComment #34
smustgrave commentedLeft a comment but why are we changing a translation button, and does changing it mean we are losing coverage for when the link is "Add"
Comment #35
akhil babu@smustgrave, Thank you for the review. There was an error in
core/modules/config_translation/tests/src/Functional/ConfigTranslationUiModulesTest.phpwhich caused the test to fail. I've explained it in the merge request and also in this comment . Please review.Comment #37
smustgrave commentedCrediting @catch for taking a look at the change I had a question on.
Removing tests tag as they appear to be added.
Clearing patches for clarity as fix is in MR 6315
Tested out following the steps appears fixed to me.
Thanks!
Comment #38
larowlanFixing component and updating issue credits
Comment #39
larowlanLeft some comments on the MR
Comment #41
pooja_sharma commentedComment #42
smustgrave commentedFor the open thread in the MR.
Comment #43
pooja_sharma commentedComment #44
smustgrave commentedLooks good to me, thanks!
Comment #45
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #46
pooja_sharma commentedComment #47
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #49
prashant.cComment #50
pooja_sharma commentedTest failures issue needs to fix
Comment #51
pooja_sharma commentedComment #52
pooja_sharma commentedMoved to NR
Comment #53
smustgrave commentedRebase seems fine
Comment #55
pooja_sharma commentedTest failures resolved & pipeline passed successfully.
Please review
Comment #56
alexpottI think this is a major bug as you end up with a broken link immediately after saving an entity. Therefore backporting to 10.3.x to be included in 10.3.0 when it is released.
Committed and pushed 8448f2d14f to 11.x and e664ed0182 to 11.0.x and 4792a5ccf4 to 10.4.x and 66531e2783 to 10.3.x. Thanks!
Comment #57
alexpott