Error: Call to a member function getConfigDependencyKey() on null in web/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php

Created on 17 July 2019, over 5 years ago
Updated 27 February 2023, almost 2 years ago

Problem

I have developed a custom module with a taxonomy created by the file my_module/config/install/taxonomy.vocabulary.myVocabulary.yml .
Terms are created during the module installation in my_module/my_module.install .

With only the custom taxonomy, the custom module uninstallation is successful, and the taxonomy is deleted.

But if a custom view is referring to this custom taxonomy, the module uninstallation is failing due to the following error :

[Fri Jul 12 12:38:33.106715 2019] [php7:notice] [pid 15765] [client 127.0.0.1:42460] Error: Call to a member function getConfigDependencyKey() on null in /home/user/MyDrupal/web/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php on line 394
#0 /home/user/MyDrupal/web/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php(75): Drupal\\taxonomy\\Plugin\\views\\filter\\TaxonomyIndexTid->calculateDependencies()
#1 /home/user/MyDrupal/web/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php(93): Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase->getPluginDependencies(Object(Drupal\\taxonomy\\Plugin\\views\\filter\\TaxonomyIndexTid))
#2 [internal function]: Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase->calculatePluginDependencies(Object(Drupal\\taxonomy\\Plugin\\views\\filter\\TaxonomyIndexTid), 9)
#3 /home/user/MyDrupal/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(960): array_walk(Array, Array)
#4 /home/user/MyDrupal/web/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php(75): Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase->calculateDependencies()
[...]

Proposed resolution

I did not dig into the module uninstallation process, but I feel the taxonomy is first removed then the custom views that calculates the dependencies.
The error is raised the issue because $vocabulary is null, as mentioned in the logs

Adding a check if (null != $vocabulary) , the module is uninstalling successfully.

I attach a patch to this issue.

I have checked the file from 8.0.X to 8.8.x, the test on $vocabulary is not present, I don't know if it could be useful to apply the patch on all branches.

The same error (getConfigDependencyKey() on null in TaxonomyIndexTid.php) has been met by other people but on a different context ( 2957376 🐛 Call to a member function getConfigDependencyKey() on null in /core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php Closed: duplicate ).

🐛 Bug report
Status

Needs work

Version

10.1

Component
Taxonomy 

Last updated 2 days ago

  • Maintained by
  • 🇺🇸United States @xjm
  • 🇬🇧United Kingdom @catch
Created by

🇫🇷France glelarge Paris

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom catch
    1. +++ b/core/modules/taxonomy/tests/src/Functional/Views/MissingTaxonomyInstallation.php
      @@ -0,0 +1,55 @@
      +
      +  /**
      +   * Test that the view is installed with a missing vocabulary.
      +   *
      

      The comment doesn't seem to match the test. Also not sure the @throws is correct here, it's not an API that's just what happens when the test fails.

    2. +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyVocabularyArgumentTest.php
      @@ -78,4 +78,20 @@ public function testTermWithVocabularyArgument() {
       
      +  /**
      +   * Test that the view is deleted when the taxonomy term is.
      +   */
      

      Nit - it's a vocabulary being deleted, not a term.

      Also this isn't asserting that the view was deleted.

    Also not clear to me if both tests are needed or only one, appear to be doing the same thing?

  • Status changed to Needs review almost 2 years ago
  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States smustgrave

    You are correct @catch they are doing the same. 1 could be deleted.

  • Status changed to Needs review over 1 year ago
  • 🇺🇸United States smustgrave

    Removed 1 test.

  • Status changed to RTBC over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,284 pass
  • 🇺🇸United States dww

    Super trivial nit, otherwise this looks great. Fixing and RTBC'ing. Hope I'm not struck by lightning for this. 😂

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,303 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    57:02
    53:30
    Running
  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom catch

    This still doesn't look right to me - shouldn't the vocabulary be in the view dependencies and if so shouldn't that either prevent the vocabulary being deleted (or delete the view, although I don't think it should)? As it is we're letting the view get into an invalid state and suppressing the error.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    CI aborted
  • 🇳🇿New Zealand john pitcairn

    I'm running into this error when running the views_post_update_remove_default_argument_skip_url db update during a 9.5.11-to-10.2.2 upgrade. While the null check may indeed be masking a problem with the view config dependencies, the patch at #28 does at least allow the update to proceed.

  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    shouldn't the vocabulary be in the view dependencies and if so shouldn't that either prevent the vocabulary being deleted (or delete the view, although I don't think it should)? As it is we're letting the view get into an invalid state and suppressing the error.

    #31: As @catch already stated in #29, this ^^ needs to be addressed before going on.

  • 🇮🇳India Akhil Babu Chengannur

    I tried to reproduce this issue, but could not (Checked in 10.1.6 and 11 versions)
    Steps followed:

    • Created a custom module and added config for vocabulary 'Custm Tags' in my_module/config/install.
    # File name taxonomy.vocabulary.custom_tags.yml
    langcode: en
    status: true
    name: Custom Tags
    vid: custom_tags
    description: 'Use tags to group articles on similar topics into categories.'
    weight: 0
    dependencies:
      enforced:
        module:
          - my_module
    • Installed the module. 'Custom Tags' vocabulary got created in admin/structure/taxonomy
    • Added few terme to the vocabulary.
    • Created a view for the vocabulary

    • Uninstalled the module.

    Results:

    • 'Custom Tags' got detered from admin/structure/taxonomy
    • The view created for 'Custom Tags' also got deleted.

    The issue summary needs to be updated with the proper steps to reproduce if this issue still exists.

  • Status changed to Postponed: needs info 11 months ago
  • 🇦🇺Australia griffynh Sydney

    Hi team, this ticket came up as the #bugsmash daily triage thread.

    I'm just flagging that if we don't get an update on this within the next three months, it may be closed.

    Cheers.

Production build 0.71.5 2024