(I honestly don't know if this belongs in Views, Taxonomy, or Cache...)

If a view has an exposed term filter, the options are not updated when new terms are added to the vocabulary. Similar results when deleting or rearranging terms.

Steps to reproduce:

  1. drush si standard --account-pass=admin -y
  2. Ensure page caching is enabled (remove settings.local.php)
  3. Log in a create a view with a page display (path: /test)
  4. Add a "Has taxonomy term" filter, select the "Tags", "Dropdown", and "Show hierarchy in dropdown", click "Apply"
  5. Tick the exposed filter option, click Apply followed by Save
  6. Navigate to the /test, there no options in the filter dropdown as expected
  7. Navigate to /admin/structure/taxonomy/manage/tags/add and add a new term
  8. Navigate to /test (or refresh the tab, if you still have it up)

The newly added term does not appear. The new term appears after clearing caches.

Members fund testing for the Drupal project. Drupal Association Learn more


mikeker created an issue. See original summary.

mikeker’s picture

Title: Exposed term filter is not updated when new terms are added (caching issue?) » Exposed term filter is not updated when terms are added, deleted, or rearranged (caching issue?)
Issue summary: View changes

Updated to include deleting and rearranging terms.

Lendude’s picture

Status: Active » Needs review
Issue tags: +Needs tests
792 bytes

@mikeker nice find.

This adds the right cachetag when I export the View, but the tag never gets hit when I add a tag...it doesn't even exist in the cachetags table. But this works if I manually invalidate the tag in the database.

Cache tag:

display_plugin: page
id: page_1
display_title: Page
position: 1
display_extenders: { }
path: test-tags
max-age: -1
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user
- 'user.node_grants:view'
- 'config:taxonomy.vocabulary.tags'

So I think there might be an issue in Taxonomy too that needs to get fixed before this patch has any effect.

Lendude’s picture

691 bytes
973 bytes

Did some more digging and that tag only get invalidated when you change the actual config of the vocabulary. Apparently adding or changing terms doesn't fall under that.

There doesn't seem to be a vocabulary specific version of the 'taxonomy_term_list' tag, so the only option here would be to add that. Seems like overkill but better then looking at old content I'd guess.

The last submitted patch, 3: 2900248-3.patch, failed testing. View results

Status: Needs review » Needs work

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

Lendude’s picture

Component: views.module » taxonomy.module
Status: Needs work » Needs review
Issue tags: -Needs tests
2.01 KB
2.42 KB

Now with tests and a check if the vocab exists.

Lendude’s picture

Issue tags: +VDC

Forgot to tag VDC

Lendude’s picture

1.24 KB
2.66 KB

Now with proper Cache::mergeTags use.

dawehner’s picture

  1. +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
    @@ -385,6 +386,21 @@ public function getCacheContexts() {
    +    // There is no vocabulary specific tag for 'taxonomy_term_list' so we add
    +    // the generic tag here to catch any updates to terms.
    +    $tags = Cache::mergeTags($tags, ['taxonomy_term_list']);
    +    return $tags;

    I think this generic list cache tag is totally fine, especially because terms don't change constantly.

  2. +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidFilterTest.php
    @@ -153,4 +153,21 @@ public function testPostUpdateFunction() {
    +  /**
    +   * Tests that the cache tags for the chosen vocabulary are added.
    +   */
    +  public function testGetCacheTags() {
    +    /** @var \Drupal\views\Entity\View $view */
    +    $view = View::load('test_filter_taxonomy_index_tid');
    +    $view_executable = $view->getExecutable();
    +    $view_executable->initDisplay();
    +    $cache_metadata = $view_executable->getDisplay()->calculateCacheMetadata();
    +    $expected_cache_tags = [
    +      'config:taxonomy.vocabulary.tags',
    +      'taxonomy_term_list',
    +    ];
    +    $this->assertEquals($expected_cache_tags, $cache_metadata->getCacheTags());
    +  }

    I think we should have a test which fails without the fix but more from a user point of view, aka. ensure that the terms are always up to date. Do you think this makes sense?