Problem/Motivation

When a taxonomy term has two parents and one of them is deleted, the reference from the child term to the now-deleted parent term still exists in taxonomy_term_hierarchy table. For example (from #20):

To test:

  1. Create "Term 1" with no parent
  2. Create "Term 2" with no parent
  3. Create "Term 3" with parents "Term 1" AND "Term 2"
  4. Delete "Term 2"

After Step 3, the taxonomy_term_hierarchy table will look like so (using theoretical tids that correspond to their names):

tid parent
1 0
2 0
3 1
3 2


After Step 4, the taxonomy_term_hierarchy table will look like so:

tid parent
1 0
3 1
3 2


In the third row "Term 2" is still listed as a parent, even though it no longer exists.

Proposed resolution

When deleting a term, delete all rows within taxonomy_term_hierarchy that list that term as a parent.

If it only has one child term, that child term will be deleted. This works. We don't need to worry about that.

Original report by nargiza

I noticed that if we have a taxonomy structure like this in table term_hierarchy:

tid parent
term1 0
term2 0
term3 term1
term3 term2

where term3 has multiple parents. If we delete, for example, term1 we obtain this result:

tid parent
term2 0
term3 term1
term3 term2

But, I don't understand why the second record is not deleted. I think it is a bug because we don't need this record anymore.

In the taxonomy module (file taxonomy.module), in function taxonomy_del_term(), after these lines:

if (count($parents) == 1) {
 $orphans[] = $child->tid;
}

we can put this:

else if (count($parents) > 1)
{
     db_query('DELETE FROM {term_hierarchy} WHERE parent = %d', $t);
} 

and, in this case, this record will be deleted too.

CommentFileSizeAuthor
#120 726490-120.patch570 bytesimmaculatexavier
#109 726490-109.patch4.17 KBMunavijayalakshmi
#108 interdiff-726490-84-108.txt962 bytesnetlooker
#108 726490-108.patch4.37 KBnetlooker
#103 726490-103.patch4.38 KBnetlooker
#99 726490-99.patch4.09 KBnetlooker
#84 726490-84.patch4.12 KBlokapujya
#84 726490-84-interdiff.txt713 byteslokapujya
#84 726490-84-test-only.patch993 byteslokapujya
#81 726490-79.patch4.09 KBlokapujya
#81 726490-81-test-only.patch969 byteslokapujya
#79 726490-79.patch4.09 KBlokapujya
#79 726490-79-interdiff.txt675 byteslokapujya
#78 726490-78-interdiff.txt644 byteslokapujya
#78 726490-78.patch4.13 KBlokapujya
#76 726490-76.patch4.13 KBlokapujya
#74 726490.74.patch4.12 KBalexpott
#74 68-74-interdiff.txt3.16 KBalexpott
#72 726490-68.patch-after.png53.43 KBleslieg
#72 726490-68.patch-before.png117.18 KBleslieg
#68 interdiff-726490-68.txt1.86 KBlokapujya
#68 726490-68.patch3.22 KBlokapujya
#65 after-delete.png23.76 KBarunkumark
#65 listofterms.png5.33 KBarunkumark
#65 create child-.png25.11 KBarunkumark
#62 interdiff-726490-60-62.txt683 byteser.pushpinderrana
#62 726490-62.patch3.45 KBer.pushpinderrana
#60 726490-60.patch3.45 KBlokapujya
#60 interdiff-726490-60.txt1.04 KBlokapujya
#57 interdiff-726490-57.txt633 byteslokapujya
#57 726490-57.patch3.76 KBlokapujya
#56 interdiff-726490-56.txt688 byteslokapujya
#56 726490-56.patch3.69 KBlokapujya
#54 interdiff-726490-54.txt925 byteslokapujya
#54 726490-54.patch3.69 KBlokapujya
#48 taxonomy-8.x-multiple-parents-726490-48.patch2.78 KBnmeegama
#48 interdiff-726490-46-48.txt2.79 KBnmeegama
#46 726490-46.patch1.79 KBlokapujya
#44 taxonomy-6.x-multiple-parents-726490-44-do-not-test.patch676 bytesguschilds
#43 taxonomy-7.x-multiple-parents-726490-43-do-not-test.patch593 bytesguschilds
#41 taxonomy-multiple-parents-726490-41.patch657 bytesjoshi.rohit100
#38 taxonomy-multiple-parents-726490-38.patch543 bytesguschilds
#36 taxonomy-multiple-parents-726490-36.patch626 bytesjoshi.rohit100
#27 taxonomy-multiple-parents-726490-26.patch2.28 KBkasperg
#20 taxonomy-multiple-parents-726490-20.patch647 bytesguschilds
#15 taxonomy-multiple-parents-726490-15.patch1.48 KBguschilds
#9 multiple_parents-726490-9.patch5.15 KBtheduke
#8 multiple_parents-726490-8.patch1.11 KBoriol_e9g
#6 multiple_parents-726490-5.patch1.11 KBtheduke
#5 multiple_parents-726490-5.patch1.11 KBtheduke
#2 multiple-parents-726490-2.patch1.26 KBdavisben
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

franz’s picture

Version: 6.15 » 8.x-dev
Issue tags: +Needs backport to D6, +Novice, +Needs backport to D7

That looks like a good patch to make.

In Drupal 7/8 the function was renamed to taxonomy_term_delete()

davisben’s picture

Status: Active » Needs review
FileSize
1.26 KB

Here's a patch.

Status: Needs review » Needs work

The last submitted patch, multiple-parents-726490-2.patch, failed testing.

franz’s picture

10oclock, I think you need to review the current tests and potentially write a new one for this case.

theduke’s picture

I created a patch against current 8.x,
with extended comments and a tid condition to avoid side effects.

theduke’s picture

Status: Needs work » Needs review
FileSize
1.11 KB

Re-submitting previous patch for Testbot.

franz’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
+++ b/core/modules/taxonomy/taxonomy.module
@@ -763,11 +763,20 @@ function taxonomy_term_delete($tid) {
+            	db_delete('taxonomy_term_hierarchy')

Should use proper softabs here

And we still needs tests.

oriol_e9g’s picture

Proper patch, we still need tests.

Tabs and 'else if' should be 'elseif'.

theduke’s picture

Status: Needs work » Needs review
FileSize
5.15 KB

I changed to elseif and wrote two new tests for Taxonomy:

testTermDeleteSingleParent checks that orphans get properly deleted when there is only one parent (no testing for this yet).
testTermDeleteMultipleParents checks that a term is not deleted when it has another parent, but that the parent reference gets deleted.

I did look over the taxonomy tests, but do not have much familiarity with the conventions for testing in core.
I hope my tests are alright.

Kristen Pol’s picture

Title: multiple parents not removed properly » Taxonomy term record for term with multiple parents is not deleted when parent is deleted
Kristen Pol’s picture

Status: Needs review » Needs work

I didn't try out the patch, but here's some feedback on styling.

+++ b/core/modules/taxonomy/taxonomy.module
@@ -763,11 +763,20 @@ function taxonomy_term_delete($tid) {
+            // If the child has multiple parents,
+            // we do not delete it, but we remove the parent reference.

Comment needs better wrapping (move some of 2nd line to first line).

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+    * Test taxonomy behaviour when deleting terms in a hierarchy with ¶
+    * a linear structure (only one parent per term).

1) "behaviour" => "behavior" for American English.

2) Extra space at end of line (after "with").

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+     // $term[3] is a child of 2.
+     $term[3]->parent = array($term[2]->tid);
+     taxonomy_term_save($term[3]);

For consistency, add new line after this section.

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+     // $term[4] is a child of 3.
+     $term[4]->parent = array($term[3]->tid);
+     taxonomy_term_save($term[4]);

For consistency, add new line after this section.

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+     $this->assertFalse($termOne, 'Child of term was automatically deleted on parent deletion.');

Exceed 80 characters.

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+     $terms = taxonomy_term_load_multiple(array($term[3]->tid, $term[4]->tid, $term[5]->tid));

Exceed 80 characters.

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+     $this->assertTrue(empty($terms), 'Children of term were automatically deleted on parent deletion.');

Exceed 80 characters.

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+   * Test taxonomy behaviour when deleting terms in a hierarchy with

1) "behaviour" => "behavior"

2) Sentence can wrap better (move part of 2nd line up to 1st line).

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+     // $term[2] is a child of 0 and 1.
+     $term[2]->parent = array($term[0]->tid, $term[1]->tid);
+     taxonomy_term_save($term[2]);

Add space after section for consistency.

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+     // Ensure that a child term does NOT get auto-deleted when it has another parent,

Exceeds 80 characters.

+++ b/core/modules/taxonomy/taxonomy.test
@@ -484,6 +484,97 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
+     $this->assertFalse(empty($children), 'Child of term was not deleted since it had another parent.');

Exceeds 80 characters.

tmckeown’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Closed (cannot reproduce)

This issue was fixed in D8 when taxonomy terms became entities. Please see issue 1361232. Need to roll a patch for D7.

tmckeown’s picture

Status: Closed (cannot reproduce) » Active

Sorry didn't mean to close the bug.

disasm’s picture

The original issue at the top expected term3 to no longer have a parent of term1 after term1 was deleted, but the current behavior deletes term3. Is this a bug? Should a term only be deleted if it has no other parents?

This was tested in 8.x.

Current behavior:

1. add term1 with no parent
2. add term2 with no parent
3. add term3 with parent of term1 and term2
4. remove term1

result: only term2 exists

Also happens if you remove term2:

1. add term1 with no parent
2. add term2 with no parent
3. add term3 with parent of term1 and term2
4. remove term2

result: only term1 exists

guschilds’s picture

Version: 7.x-dev » 8.x-dev
Status: Active » Needs review
FileSize
1.48 KB

The bug originally described no longer exists because a term with two parents is getting incorrectly deleted when only one of its parents is deleted, as described in #14.

This happened because postDelete of a parent term in TermStorageController.php considered a child term with <= 1 parent to be an orphan. Because it is postDelete, the parent term in question has already been removed, so the child term being examined is only an orphan if there are 0 parents.

This is fixed in the attached patch.

Upon fixing this, the bug originally described resurfaced. Records referencing deleted terms as parents still exist. This is because records are only removed by searching the tid column when a term is removed. When a term has multiple parents, and one of them is deleted, it will still list that deleted term as a parent unless it itself is removed later.

The attached patch also deletes all records that list a term being deleted as a parent.

First core patch attempt. :)

mkostrzewa’s picture

Tested the patch and it did fix the issue mentioned in #14

Here is the testing process

Added the following:

  1. term1 - no parent
  2. term2 - no parent
  3. term3 - parent of term 1 and 2

Action: deleted term1
Result: only term2 left

and vice versa

After applying patch taxonomy-multiple-parents-726490-15.patch

Action: deleted term1
Result: term2 term3

Action: deleted term2
Result: term1 term3

druderman’s picture

I looked over the comments on this issue and it appears that the "Needs tests" tag can be removed.

franz’s picture

druderman, "Needs tests" doesn't refer to manual testing. It refers to adding automated tests to this patch, in the way it is described on the docs: http://drupal.org/project/issues/search/drupal?issue_tags=Needs+tests

franz’s picture

@guschilds, I think it's better to add a new issue as a spin-off of this one, and when it's fixed, we come back to this.

guschilds’s picture

Following franz's suggestion, I have created #2077387: Taxonomy term is improperly deleted when only one of two parents is deleted to address the bug described in #14-16 of this issue.

Once that bug is addressed, the bug originally described in this issue does resurface in Drupal 8. The attached patch fixes it.

To test:

  1. Create "Term 1" with no parent
  2. Create "Term 2" with no parent
  3. Create "Term 3" with parents "Term 1" AND "Term 2"
  4. Delete "Term 2"

After Step 3, the taxonomy_term_hierarchy table will look like so (using theoretical tids that correspond to their names):

tid parent
1 0
2 0
3 1
3 2


After Step 4, the taxonomy_term_hierarchy table will look like so:

tid parent
1 0
3 1
3 2


In the third row "Term 2" is still listed as a parent, even though it no longer exists. That is the bug originally reported.

After implementing the patch in #2077387: Taxonomy term is improperly deleted when only one of two parents is deleted, applying the attached patch here, and re-testing the instructions, the taxonomy_term_hierarchy table will look like so after Step 4:

tid parent
1 0
3 1


"Term 2" was successfully removed from the records as a parent.

Status: Needs review » Needs work

The last submitted patch, taxonomy-multiple-parents-726490-20.patch, failed testing.

kasperg’s picture

Assigned: Unassigned » kasperg

I'll try to take a stab at this.

timdavison’s picture

Assigned: kasperg » timdavison

Im sprinting in Prague looking at this one.

kasperg’s picture

Assigned: timdavison » kasperg

After much confusion I'll reassign this back to me.

kasperg’s picture

Status: Needs work » Needs review
Issue tags: -Needs backport to D6, -Needs tests, -Novice, -Needs backport to D7

Status: Needs review » Needs work
Issue tags: +Needs backport to D6, +Needs tests, +Novice, +Needs backport to D7

The last submitted patch, taxonomy-multiple-parents-726490-20.patch, failed testing.

kasperg’s picture

Status: Needs work » Needs review
FileSize
2.28 KB

Here is a working patch based on the work in #20 which failed testing.

Note that there are no test cases for checking for the erroneous situation as there seems to be no way to retrieve data only from the taxonomy_term_hierarchy table without querying the database directly. That seems to be the wrong way to go about this.

kasperg’s picture

Issue summary: View changes

Updated issue summary.

selwynpolit’s picture

selwynpolit’s picture

selwynpolit’s picture

9: multiple_parents-726490-9.patch queued for re-testing.

selwynpolit’s picture

8: multiple_parents-726490-8.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 27: taxonomy-multiple-parents-726490-26.patch, failed testing.

The last submitted patch, 8: multiple_parents-726490-8.patch, failed testing.

The last submitted patch, 9: multiple_parents-726490-9.patch, failed testing.

The last submitted patch, 15: taxonomy-multiple-parents-726490-15.patch, failed testing.

joshi.rohit100’s picture

Issue summary: View changes
FileSize
626 bytes

Patch Submitted for D8

joshi.rohit100’s picture

Status: Needs work » Needs review
guschilds’s picture

Assigned: kasperg » Unassigned
FileSize
543 bytes

I just tested the patch from #36 and unfortunately it did not solve the problem. Following the steps outlined in the issue summary and in my description in #20, the deleted term is still listed as a parent in taxonomy_term_hierarchy when its child term had multiple parents.

I've rerolled my patch from #20, which continues to fix the original problem.

Thanks,
Gus

guschilds’s picture

Status: Needs review » Needs work

The last submitted patch, 38: taxonomy-multiple-parents-726490-38.patch, failed testing.

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
657 bytes

updated patch. Please review now.

guschilds’s picture

#41 passes tests and works. Thanks!

The only issue I'm seeing is the lack of a single space between the "//" and the comment text, "Remove...".

guschilds’s picture

Attached is a backport to D7.

I've marked it as do-not-test so it doesn't get tested against 8.x.

guschilds’s picture

Attached is a backport to D6.

I've marked it as do-not-test so it doesn't get tested against 8.x.

joachim’s picture

Status: Needs review » Needs work
+++ b/core/modules/taxonomy/taxonomy.module
@@ -837,6 +837,8 @@ function taxonomy_taxonomy_term_delete(Term $term) {
   if (\Drupal::config('taxonomy.settings')->get('maintain_index_table')) {
     // Clean up the {taxonomy_index} table when terms are deleted.
     db_delete('taxonomy_index')->condition('tid', $term->id())->execute();
+    //Remove the reference to this term by other terms.
+    db_delete('taxonomy_term_hierarchy')->condition('parent', $term->id())->execute();
   }

This is just an eyeball review, and I don't pretend to understand the code...

But it looks like this is inside a conditional check for whether the system maintains an index table.

Surely the presence of an index table is independent of the existence of the term hierarchy table?

lokapujya’s picture

Status: Needs work » Needs review
FileSize
1.79 KB

Here is another way to fix it, incase we don't want to use hook_taxonomy_term_delete.

nmeegama’s picture

Issue tags: +Amsterdam2014

I m reviewing this @amsterdam2014

nmeegama’s picture

The patch by @lokapujya works fine just a small fix though or an opinion rather. I Just think that the unparentTerms() function should not be called from the postDelete in the Term Class for the sake of best practices. one function should be called from postDelete that deletes the terms and the parent references from the term_hierarchy table so i created this patch.

lokapujya’s picture

Awe, I spent so much time coming up with the name "unparent", haha.

nmeegama’s picture

:) Unparent
With great power comes great responsibility. Sorry man

lokapujya’s picture

Status: Needs review » Needs work

So, we just need tests.

nmeegama’s picture

I will write the test on for this

lokapujya’s picture

Issue summary: View changes
lokapujya’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Amsterdam2014
FileSize
3.69 KB
925 bytes

Since the test is failing, I think we maybe didn't need the bug fix code afterall. Possibly just need to clear the storage cache. I tried calling resetcache() from post_delete() but it doesn't seem to work.

Status: Needs review » Needs work

The last submitted patch, 54: 726490-54.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
3.69 KB
688 bytes

Fix a line that shouldn't be commented out.

lokapujya’s picture

FileSize
3.76 KB
633 bytes

Clearing cache worked locally. But is it acceptable?

The last submitted patch, 56: 726490-56.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 57: 726490-57.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
1.04 KB
3.45 KB

Fix the exception.

pingers’s picture

  1. +++ b/core/modules/taxonomy/src/TermStorageInterface.php
    @@ -24,6 +24,13 @@
    +   * Removes reference to terms from term_hierarchy parent
    

    Use sentence style (period).

  2. +++ b/core/modules/taxonomy/src/TermStorageInterface.php
    @@ -24,6 +24,13 @@
    +   *  Array of parent terms that needs to be removed from hierarchy
    

    "Array of parent terms that need to be removed from hierarchy." - no plural on 'needs' and use sentence style (period).

er.pushpinderrana’s picture

FileSize
3.45 KB
683 bytes

Did changes in this patch as @pingers suggested.

Dragooon’s picture

Status: Needs review » Reviewed & tested by the community

Latest patch (#62) looks good

lokapujya’s picture

Status: Reviewed & tested by the community » Needs review

I want to get an opinion on the change in #57.

arunkumark’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
25.11 KB
5.33 KB
23.76 KB

@lokapujya #57 patch works fine and only the problem I notice Comment standards for functions ( https://www.drupal.org/coding-standards/docs#functions ). Patch #62 tested with latest version; its works fine; and I've added some screenshots of the tested patch.
Create Child:
Create child.
List of terms:
list of terms
After delete:
After delete results

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/taxonomy/src/Entity/Term.php
    @@ -77,7 +77,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
    -    $storage->deleteTermHierarchy(array_keys($entities));
    +    $storage->deleteTermsFromTermHierarchy(array_keys($entities));
    

    Let's just call both deleteTermHierarchy and deleteTermHierarchyByParent here.

  2. +++ b/core/modules/taxonomy/src/Entity/Term.php
    --- a/core/modules/taxonomy/src/TermStorage.php
    +++ b/core/modules/taxonomy/src/TermStorage.php
    
    +++ b/core/modules/taxonomy/src/TermStorageInterface.php
    @@ -24,6 +24,13 @@
    +   * Removes reference to terms from term_hierarchy parent.
    +   * @param array $pids
    

    Needs an empty line between method description and @param doc.

  3. +++ b/core/modules/taxonomy/src/TermStorage.php
    @@ -106,6 +106,23 @@ public function deleteTermHierarchy($tids) {
    +  /**
    +   * Removes the terms and reference to parents from term_hierarchy.
    +   */
    +  public function deleteTermsFromTermHierarchy($tids) {
    

    This should be on the interface no? But actually I think we should not introduce this because it is hard to explain the difference from deleteTermHierarchy

lokapujya’s picture

No one seems concerned that a resetCache is required in the test after deleting a term (see change in #57)? If that turns out to be a problem, we could open a new issue.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
3.22 KB
1.86 KB

Made the suggested changes from #66.

leslieg’s picture

Assigned: Unassigned » leslieg
disasm’s picture

Issue tags: -Novice

I am removing the Novice tag from this issue because there are no novice action items for this task.

I’m using this documentation as a source: https://www.drupal.org/core-mentoring/novice-tasks#avoid

lokapujya’s picture

Talked to Wim Leers about the resetCache() concern that I brought up in #57 and #67. It is due to static cache, and it's only necessary during the test because of use of the variable in the same request.

leslieg’s picture

Issue summary: View changes
FileSize
117.18 KB
53.43 KB

Tested against latest head version with 726490-68.patch applied

Screenshot of database after deleting term 2 before patch (726490-68.patch-before.png) and after deleting term 2 after patch (726490-68.patch-after.png) are attached.

Both references to term 2 are now correctly deleted from the database.

leslieg’s picture

Assigned: leslieg » Unassigned
Status: Needs review » Reviewed & tested by the community

Reviewed and passed in D8

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.16 KB
4.12 KB

I think we can do better by reorganising updateTermHierarchy and deleteTermHierarchy. This way we can optimise the delete with an or and encapsulate the update nicely. Also having deleteTermHierarchy and deleteTermHierarchyByParent is very confusing.

See patch attached for what I'm on about.

mgifford’s picture

Status: Needs review » Needs work

Patch no longer applies.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
4.13 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 76: 726490-76.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
4.13 KB
644 bytes
lokapujya’s picture

jibran’s picture

Can we have a test only patch to see the bug?

lokapujya’s picture

jibran’s picture

Status: Needs review » Reviewed & tested by the community

RTBC if red and green. Thanks.

oriol_e9g’s picture

Status: Reviewed & tested by the community » Needs work

Test only green :(

lokapujya’s picture

Since https://www.drupal.org/node/1976298, loadParents() now returns the term objects. So, the DB is still wrong, but loadParents() masks the bug. Modified the test to just load the hierarchy.

The last submitted patch, 84: 726490-84-test-only.patch, failed testing.

jibran’s picture

+++ b/core/modules/taxonomy/src/Tests/TermTest.php
@@ -116,6 +116,16 @@ function testTaxonomyTermHierarchy() {
+    $parents = $taxonomy_storage->loadTree($this->vocabulary->id(), $term3->id());

$term is deleted so using its id here doesn't make sense.

lokapujya’s picture

Well, that's the point. loadTree() shouldn't find anything for that term, but it does.

loadParents() doesn't show the bug anymore. In order to have a test only that fails, I used loadTree(). Instead of loadTree(), the test could do a Select on taxonomy_term_field_data? I was trying to find a way to use the API rather than do a select.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

No one seems concerned that a resetCache is required in the test after deleting a term (see change in #57)?

That is concerning, and probably means that a cache tag on the child needs to be invalidated instead.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

suresh_ewall’s picture

Assigned: Unassigned » suresh_ewall
Status: Needs review » Reviewed & tested by the community

Hi,

We have tested the mentioned patch and reviewed that patch. Everything seems working fine. Thanks for the patch.

suresh_ewall’s picture

Hi,

We have tested the mentioned patch and reviewed that patch. Everything seems working fine. Thanks for the patch.

The last submitted patch, 44: taxonomy-6.x-multiple-parents-726490-44-do-not-test.patch, failed testing.

The last submitted patch, 43: taxonomy-7.x-multiple-parents-726490-43-do-not-test.patch, failed testing.

alexpott’s picture

Assigned: suresh_ewall » Unassigned
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
+++ b/core/modules/taxonomy/src/Tests/TermTest.php
@@ -116,6 +116,16 @@ function testTaxonomyTermHierarchy() {
+    // Check the hierarchy after deleting one parent of multiple parents.
+    $taxonomy_storage->resetCache();
+    $parents = $taxonomy_storage->loadTree($this->vocabulary->id(), $term3->id());
+    $this->assertTrue(count($parents) == 0, 'Term 3 has no lineage.');

We need more tests here. We're not actually testing the hierarchy after deleting a parent. We also need to check the hierarchy of $term2 which had $term3 and $term1 as parents but now should only have $term1.

We need a reroll too. Given that this has needs a reroll since:

commit 367c98f45c3fd1718d1605a600f6ed367a03862c
Author: Alex Pott <alex.a.pott@googlemail.com>
Date:   Fri Oct 21 06:28:02 2016 -0700

    Issue #2761059 by govind.maloo, arunkumark, tstoeckler: Term::postDelete() needlessly uses entity_delete_multiple()

I'm not sure what was reviewed in #91? Was the code applied and core functionality tested? It is great to document what you have done when you rtbc a patch.

netlooker’s picture

I've applied patch https://www.drupal.org/files/issues/726490-84.patch without any issues. I've also performed all tests for the taxonomy and no issues here as well. It seems that there is no need to reroll the patch at least for the recent D8 version.

alexpott’s picture

Version: 8.2.x-dev » 8.4.x-dev

@netlooker this needs to be applied to 8.4.x first and then 8.3.x (since it is a bug fix without BC implication as far as I can see). Although one reason it might not get in to 8.3.x is that we really should have an upgrade path to remove entries where the term ID no longer exists.

Anyways the patch in #84 does not apply to 8.4.x or 8.3.x.

netlooker’s picture

@alexpott thanks for clarifying. I will work on it today most probably in the evening.

netlooker’s picture

I've rerolled the patch for the 8.4.x branch. I've also performed all tests for the taxonomy and all of them are green.
This patch is also applicable to the 8.3.x branch and taxonomy tests are green as well.

netlooker’s picture

Issue tags: -Needs reroll
lokapujya’s picture

Thanks @netlooker,

Can you try adding the tests mentioned in #95?

netlooker’s picture

@lokapujya ok, I will try and keep you posted.

netlooker’s picture

I've prepared the following patch with the test which checks if there is an existing parent ($term1). I've checked the results and I didn't find any issues. @lokapujya please let me know if it is enough or did I miss something :)

lokapujya’s picture

Status: Needs work » Needs review

You need to set to "Needs Review" so that the patch gets tested. Also, can you provide an interdiff so that we can see the changes?

lokapujya’s picture

Status: Needs review » Needs work
+++ b/core/modules/taxonomy/src/Tests/TermTest.php
@@ -111,6 +111,21 @@ function testTaxonomyTermHierarchy() {
+    $this->assertTrue(isset($parents[$term1->id() && count($parents) == 1]), 'Existing parent found successfully.');

The [] brackets are wrong. As is, the condition is inside the [].

lokapujya’s picture

+++ b/core/modules/taxonomy/src/Tests/TermTest.php
@@ -111,6 +111,21 @@ function testTaxonomyTermHierarchy() {
+    // Check the hierarchy after deleting for the existing parent ($term1).

Also, I recommend rewording the comment. Maybe change "deleting" to "deletion". I also wouldn't put the variable name in the comment, because then if the code changes, the comment has to get changed too.

netlooker’s picture

Thanks for the valuable feedback. I will implement your suggestions.

netlooker’s picture

Status: Needs work » Needs review
FileSize
4.37 KB
962 bytes

@lokapujya I've added given suggestions and created interdiff between #84 and the latest version of the patch.

Munavijayalakshmi’s picture

Rerolled the patch.

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.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.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.

larowlan’s picture

Adding some tags

immaculatexavier’s picture

Backported to D7

immaculatexavier’s picture

Status: Needs review » Patch (to be ported)
Issue tags: -Needs backport to D7
immaculatexavier’s picture

Status: Patch (to be ported) » Needs review

@larowlan #120 - Backported to D7

Lendude’s picture

Status: Needs review » Closed (outdated)
Issue tags: -Needs backport to D6

I've manually tested this and this no longer occurs, there are no longer any orphaned records after deleting one of two parents.

Also verified this by running the automated test, it is green on HEAD.

Closing this as outdated for now, if you feel this is still an issue, feel free to re-open this issue.