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.

https://www.drupal.org/files/issues/2024-01-25/local-task-cache-not-invalidated.gif

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

Issue fork drupal-2927141

Command icon 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

geertvd created an issue. See original summary.

geertvd’s picture

Did 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():

$cacheability->addCacheableDependency($access)->addCacheableDependency($child);

The above snippet is executed for all the local tasks within 1 local tasks block. For a local task block on nodes these are:

- entity.node.canonical
- entity.node.edit_form
- entity.node.delete_form
- entity.node.version_history

The node cache tag is only added because of the last local task (entity.node.version_history), it is passed in the $access parameter.

Checking the access handler for the entity.node.version_history route (NodeRevisionAccessCheck) shows that the node's cache tag is added in it's access-result:

return AccessResult::allowedIf($node && $this->checkAccess($node, $account, $operation))->cachePerPermissions()->addCacheableDependency($node);

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.

geertvd’s picture

Assigned: Unassigned » geertvd

Just working on some tests for this.

geertvd’s picture

Status: Active » Needs review
StatusFileSize
new1.83 KB
new2.49 KB

Test + quick fix, this will probably break some other tests.

Status: Needs review » Needs work

The last submitted patch, 4: 2927141-4.patch, failed testing. View results

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jeroent’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

I 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.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Version: 9.5.x-dev » 10.0.x-dev
Assigned: geertvd » Unassigned
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work
Issue tags: +Needs reroll

@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.

ravi.shankar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new2.5 KB
new1.24 KB

Added reroll of patch #4 on Drupal 10.0.x.

jeroent’s picture

Status: Needs review » Needs work
detroz’s picture

StatusFileSize
new2.55 KB

I 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).

akhil babu’s picture

Version: 10.0.x-dev » 11.x-dev
akhil babu’s picture

StatusFileSize
new1.22 MB

I tested this issue in Drupal 11 and it is still reproducible. Unlike #2, this issue was reproducible for nodes as well.

  • 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.

https://www.drupal.org/files/issues/2024-01-25/local-task-cache-not-invalidated.gif

akhil babu’s picture

However, 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_access and it adds the entity as a cachable dependency to the access result.

function content_moderation_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  /** @var \Drupal\content_moderation\ModerationInformationInterface $moderation_info */
  $moderation_info = Drupal::service('content_moderation.moderation_information');

  $access_result = NULL;
  if ($operation === 'view') {
    $access_result = (($entity instanceof EntityPublishedInterface) && !$entity->isPublished())
      ? AccessResult::allowedIfHasPermission($account, 'view any unpublished content')
      : AccessResult::neutral();

    $access_result->addCacheableDependency($entity);
  }
//

akhil babu’s picture

Patch #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.

akhil babu’s picture

Title: Taxonomy local tasks not updated after changing a term's URL alias » Updates to an entity's URL alias do not reflect on the corresponding local tasks.
Issue summary: View changes
akhil babu’s picture

Issue summary: View changes
akhil babu’s picture

The new change caused only one test failure .

Drupal\Tests\config_translation\Functional\ConfigTranslationUiModulesTest::testNodeFieldTranslation
Behat\Mink\Exception\ExpectationException: The string "FR label" was not found anywhere in the HTML response of the current page.

The test makes a field translatable and tries to add 'French' translation to it's label and help text.

    $this->drupalGet("/entity_test/structure/article/fields/node.article.$field_name/translate");
    $this->clickLink('Add');

    $form_values = [
      'translation[config_names][field.field.node.article.translatable_field][description]' => 'FR Help text.',
      'translation[config_names][field.field.node.article.translatable_field][label]' => 'FR label',
    ];
    $this->submitForm($form_values, 'Save translation');
    $this->assertSession()->pageTextContains('Successfully saved French translation.');

Then it checks if the translation is saved or not.

    // Check that the translations are saved.
    $this->clickLink('Add');
    $this->assertSession()->responseContains('FR label');

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.

akhil babu’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests

This needs tests. But temporarly moving to needs review for core maintainers to check the proposed solution and provide further guidance.

Akhil Babu changed the visibility of the branch 2927141-taxonomy-local-tasks to hidden.

Akhil Babu changed the visibility of the branch 2927141-taxonomy-local-tasks to active.

smustgrave’s picture

Status: Needs review » Needs work

Appears to have a test failure.

Have not retested.

akhil babu’s picture

When a node/taxonomy term is created with an alias like this

$this->drupalCreateNode([
        'type' => 'article',
        'path' => [
          'alias' => '/original-node-alias',
        ],
])

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.

   Failed asserting that two strings are identical.
    --- Expected
    +++ Actual
    @@ @@
    -'/original-node-alias'
    +'/subdirectory/original-node-alias'

I believe this issue arises because SIMPLETEST_BASE_URL is set as http://localhost/subdirectory in pipeline.yml
So, to confirm that the link has been updated, I replaced assertSame() with assertStringContainsString() in the test. Pipeline is up now.

akhil babu’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Left 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"

akhil babu’s picture

Status: Needs work » Needs review

@smustgrave, Thank you for the review. There was an error incore/modules/config_translation/tests/src/Functional/ConfigTranslationUiModulesTest.php which caused the test to fail. I've explained it in the merge request and also in this comment . Please review.

smustgrave credited catch.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests +Needs Review Queue Initiative

Crediting @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!

larowlan’s picture

Component: path.module » base system

Fixing component and updating issue credits

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Left some comments on the MR

pooja_sharma made their first commit to this issue’s fork.

pooja_sharma’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

For the open thread in the MR.

pooja_sharma’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, thanks!

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The 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.

pooja_sharma’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The 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.

Prashant.c made their first commit to this issue’s fork.

prashant.c’s picture

Status: Needs work » Needs review
pooja_sharma’s picture

Status: Needs review » Needs work

Test failures issue needs to fix

pooja_sharma’s picture

Status: Needs work » Needs review
pooja_sharma’s picture

Moved to NR

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems fine

alexpott made their first commit to this issue’s fork.

pooja_sharma’s picture

Test failures resolved & pipeline passed successfully.

Please review

alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Priority: Normal » Major
Status: Reviewed & tested by the community » Fixed

I 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!

alexpott’s picture

  • alexpott committed 66531e27 on 10.3.x
    Issue #2927141 by Akhil Babu, pooja_sharma, geertvd, smustgrave, JeroenT...

  • alexpott committed 4792a5cc on 10.4.x
    Issue #2927141 by Akhil Babu, pooja_sharma, geertvd, smustgrave, JeroenT...

  • alexpott committed e664ed01 on 11.0.x
    Issue #2927141 by Akhil Babu, pooja_sharma, geertvd, smustgrave, JeroenT...

  • alexpott committed 8448f2d1 on 11.x
    Issue #2927141 by Akhil Babu, pooja_sharma, geertvd, smustgrave, JeroenT...

Status: Fixed » Closed (fixed)

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