Problem/Motivation

I am trying to feature module which includes vocabulary configuration and I use default_content to also create the preset terms. In my repeated experiments I notice there is no bulk method to delete al terms, but I thought that deleting the vocabulary would take care of that. (Un)fortunately this is not the case. After re-enabling the feature module I get error messages caused by duplicate UUID. I then looked in the database term table I discover that all terms are still there but orphaned from the now deleted vocabulary. I do not understand the practical advantage of these hidden terms that have become useless, occupy database space and evidently form an obstacle for testing and developping.

Steps to reproduce

  • Create a test vocabulary
  • Create some terms in the test vocabulary
  • Delete the previously created test vocabulary
  • Check with database management tool (phpmyadmin) the *term* tables and notice that still terms exist for the test vocabulary

Proposed resolution

Delete vocabulary process should include a step to also delete all its terms. There is already a warning but it should include one about the potential term loss which could include a summary list of the terms to warn users what they are doing.

Comments

ñull created an issue. See original summary.

pameeela’s picture

Title: Erase vocabulary will leave orphan terms » Deleting a vocabulary does not delete its terms
Version: 8.9.x-dev » 9.3.x-dev
Issue tags: +Bug Smash Initiative

I thought this couldn't be true! It definitely wasn't true in D7, but it does seem to be the case in 8/9.

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

According to \Drupal\taxonomy\Entity\Vocabulary::preDelete(), no that shouldn't happen. What parent value do these leftover terms have, is something wrong with the top level tids detection or does it not delete some childs? Is it a problem with the access check? that doesn't really seem realistic, someone who can delete the vocabulary must have access to the terms? That said, this is not a UI method, it could be called with config import/drush where it might not be an authenticated user.

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.

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.

kristen pol’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Thanks for reporting this issue. We rely on issue reports like this one to resolve bugs and improve Drupal core.

As part of the Bug Smash Initiative, we are triaging issues that are marked "Postponed (maintainer needs more info)". This issue was marked "Postponed (maintainer needs more info)" more than a year ago.

Using the steps from the issue summary, I was unable to reproduce the issue. I tested as follows:

  1. Install 9.3
  2. Create test vocabulary
  3. Add several terms
  4. Delete the vocabulary
  5. Check the database
  6. Result: I don't see any term data in the database
MariaDB [db]> select * from taxonomy_term_data;
Empty set (0.001 sec)

MariaDB [db]> select * from taxonomy_term_field_data;
Empty set (0.001 sec)

MariaDB [db]> select * from taxonomy_term_field_revision;
Empty set (0.001 sec)

MariaDB [db]> select * from taxonomy_term_revision;
Empty set (0.001 sec)

MariaDB [db]> select * from taxonomy_term_revision__parent;
Empty set (0.001 sec)

MariaDB [db]> select * from taxonomy_term__parent;
Empty set (0.001 sec)

MariaDB [db]> select * from taxonomy_index;
Empty set (0.001 sec)

Since I couldn't reproduce this issue and this was postponed more than a year ago and has no activity since that time, I'm marking the issue "Closed (cannot reproduce)". If anyone can provide complete steps to reproduce the issue (starting from "Install Drupal core"), document those steps in the issue summary and set the issue status back to "Active".

Thanks!