Download & Extend

deleting nodes does not delete their comments.

Project:Drupal core
Version:7.x-dev
Component:comment.module
Category:task
Priority:critical
Assigned:Unassigned
Status:closed (fixed)
Issue tags:needs backport to D7, Novice

Issue Summary

Deleting nodes via devel generate does not delete the comments on those nodes.

Comments

#1

Project:Devel» Drupal core
Version:7.x-1.x-dev» 7.x-dev
Component:devel_generate» comment.module
Priority:normal» critical
Assigned to:Anonymous» moshe weitzman
Status:active» needs review

Oh for fucks sake. You just found a critical core bug. Deleting a single node via the UI created orphaned comment records. Maybe D7 isn't so ready after all.

The problem is that we delete from node table and then we call the hook where comment_load_multiple() fires. But it can't load any comments because the node record is gone.

Seems like we should just delete from node table after calling the hooks. Attached patch does that.

AttachmentSizeStatusTest resultOperations
ndm_reorder.diff1.85 KBIdleFAILED: [[SimpleTest]]: [MySQL] 23,294 pass(es), 1 fail(s), and 0 exception(es).View details

#2

Status:needs review» needs work

+++ modules/comment/comment.module
@@ -1641,6 +1641,7 @@ class CommentController extends DrupalDefaultEntityController {
+    print_r((string)$query);

debug statement to remove.

+++ modules/node/node.module
@@ -1162,6 +1152,17 @@ function node_delete_multiple($nids) {
+    ¶
+    // Delete after calling hooks so that they can query node tables as needed.
+    db_delete('node')
+      ->condition('nid', $nids, 'IN')
+      ->execute();

whitespace issue

patch works otherwise.

#3

Status:needs work» needs review

fixed those. thanks.

AttachmentSizeStatusTest resultOperations
ndm_reorder.diff1.31 KBIdlePASSED: [[SimpleTest]]: [MySQL] 23,291 pass(es).View details

#4

Status:needs review» reviewed & tested by the community

looks good.

#5

Priority:critical» normal
Status:reviewed & tested by the community» needs work

Nicely spotted, Jen. :)

Committed to HEAD to clear out the critical. However, this is a really stupid bug and we should make sure we don't ever have it again. Tests, please!

#7

Title:deleting nodes does not delete their comments.» (Tests needed) deleting nodes does not delete their comments.
Version:7.x-dev» 8.x-dev
Category:bug report» task
Issue tags:+needs backport to D7

#8

Status:needs work» needs review

I'm sick of seeing this issue in my tracker ;) Will this test work? I've generalized the test case, so that other test methods can be added to it that tests if comments behave correctly after a node changes.

AttachmentSizeStatusTest resultOperations
D8-tests-for-comment-deletion-890790-8.patch1.14 KBIdleFAILED: [[SimpleTest]]: [MySQL] 35,396 pass(es), 1 fail(s), and 0 exception(s).View details

#9

Status:needs review» needs work

The last submitted patch, D8-tests-for-comment-deletion-890790-8.patch, failed testing.

#10

Status:needs work» needs review

*coughs*

AttachmentSizeStatusTest resultOperations
D8-tests-for-comment-deletion-890790-10.patch1.11 KBIdleFAILED: [[SimpleTest]]: [MySQL] 35,409 pass(es), 1 fail(s), and 0 exception(s).View details

#11

Status:needs review» needs work

The last submitted patch, D8-tests-for-comment-deletion-890790-10.patch, failed testing.

#12

Status:needs work» needs review

Mhmm, bill me for the wasted testbot server time.

AttachmentSizeStatusTest resultOperations
D8-tests-for-comment-deletion-890790-12.patch1.14 KBIdleFAILED: [[SimpleTest]]: [MySQL] 35,393 pass(es), 10 fail(s), and 4 exception(s).View details

#13

Status:needs review» needs work

The last submitted patch, D8-tests-for-comment-deletion-890790-12.patch, failed testing.

#14

Status:needs work» needs review

Let's try with a user that has permission to post comments *blushes*

AttachmentSizeStatusTest resultOperations
D8-tests-for-comment-deletion-890790-14.patch1.18 KBIdleFAILED: [[SimpleTest]]: [MySQL] 35,427 pass(es), 1 fail(s), and 2 exception(s).View details

#15

Status:needs review» needs work

The last submitted patch, D8-tests-for-comment-deletion-890790-14.patch, failed testing.

#16

Status:needs work» needs review
AttachmentSizeStatusTest resultOperations
D8-tests-for-comment-deletion-890790-16.patch1.18 KBIdlePASSED: [[SimpleTest]]: [MySQL] 35,418 pass(es).View details

#17

Status:needs review» reviewed & tested by the community

The test works like it's supposed to.

#18

Status:reviewed & tested by the community» needs work

The test looks good, but now that #1477218: Convert Tracker tests to PSR-0 / PSR-0 test class discovery is in, we should start ensuring that new test classes that are added are PSR-0 so we don't need to go back and convert them again later.

#19

Sure, makes sense. I'll reroll it.

#20

Status:needs work» needs review

I'm probably doing something fundamentally wrong here. It's not working.

AttachmentSizeStatusTest resultOperations
D8-tests-for-comment-deletion-890790-20.patch1.31 KBIdleFAILED: [[SimpleTest]]: [MySQL] Failed to run tests: failed during invocation of run-tests.sh.View details

#21

Status:needs review» needs work

The last submitted patch, D8-tests-for-comment-deletion-890790-20.patch, failed testing.

#22

Status:needs work» needs review

Not working with CommentHelperCase (now named CommentTestBase) namespaced either.

AttachmentSizeStatusTest resultOperations
D8-tests-for-comment-deletion-890790-22.patch24.07 KBIdleFAILED: [[SimpleTest]]: [MySQL] Failed to run tests: failed during invocation of run-tests.sh.View details

#23

Status:needs review» needs work

The last submitted patch, D8-tests-for-comment-deletion-890790-22.patch, failed testing.

#24

Assigned to:moshe weitzman» dags

#25

The use path was incomplete. Let's see if this works.

AttachmentSizeStatusTest resultOperations
d8-tests-for-comment-deletion-890790-25.patch24.07 KBIdleFAILED: [[SimpleTest]]: [MySQL] Failed to run tests: failed during invocation of run-tests.sh.View details
interdiff.txt417 bytesIgnored: Check issue status.NoneNone

#26

Status:needs work» needs review

#27

Status:needs review» needs work

The last submitted patch, d8-tests-for-comment-deletion-890790-25.patch, failed testing.

#28

Oh yes, right you are. It will need to be changed in core/modules/comment/lib/Drupal/comment/Tests/CommentNodeChangesTest.php as well.

#29

Also, it looks like tests for other core modules are using CommentHelperCase, so those need to be updated as well:

grep -rl "CommentHelperCase" .
./core/modules/rdf/rdf.test
./core/modules/user/user.test

#30

Changes from #28 & #29. Interdiff against #22.

AttachmentSizeStatusTest resultOperations
d8-tests-for-comment-deletion-890790-30.patch25.06 KBIdleFAILED: [[SimpleTest]]: [MySQL] Failed to run tests: failed during invocation of run-tests.sh.View details
interdiff.txt1.9 KBIgnored: Check issue status.NoneNone

#31

Status:needs work» needs review

I always forget this part...

#32

Status:needs review» needs work

The last submitted patch, d8-tests-for-comment-deletion-890790-30.patch, failed testing.

#33

Status:needs work» needs review

Off by one letter.

AttachmentSizeStatusTest resultOperations
d8-tests-for-comment-deletion-890790-33.patch25.06 KBIdleFAILED: [[SimpleTest]]: [MySQL] Failed to run tests: failed during invocation of run-tests.sh.View details
interdiff.txt1.9 KBIgnored: Check issue status.NoneNone

#34

Status:needs review» needs work

Almost there.

+++ b/core/modules/rdf/rdf.testundefined
@@ -416,7 +416,7 @@ class RdfMappingDefinitionTestCase extends TaxonomyWebTestCase {
-class RdfCommentAttributesTestCase extends CommentHelperCase {
+class RdfCommentAttributesTestCase extends CommentTestCase {

   public static function getInfo() {
     return array(
diff --git a/core/modules/user/user.test b/core/modules/user/user.test

diff --git a/core/modules/user/user.test b/core/modules/user/user.test
index 7671eba..7818193 100644

index 7671eba..7818193 100644
--- a/core/modules/user/user.test

--- a/core/modules/user/user.test
+++ b/core/modules/user/user.testundefined

+++ b/core/modules/user/user.testundefined
+++ b/core/modules/user/user.testundefined
@@ -1946,7 +1946,7 @@ class UserSignatureTestCase extends WebTestBase {

@@ -1946,7 +1946,7 @@ class UserSignatureTestCase extends WebTestBase {
     $this->drupalPost(NULL, array(), t('Save'));

     // Get the comment ID. (This technique is the same one used in the Comment
-    // module's CommentHelperCase test case.)
+    // module's CommentTestCase test case.)
     preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
     $comment_id = $match[1];
Should be CommentTestBase. Also the rdf.test file should have use Drupal\comment\Tests\CommentTestBase; as well.

#35

Status:needs work» needs review

Sorry, cross-post.

#36

Status:needs review» needs work

The last submitted patch, d8-tests-for-comment-deletion-890790-33.patch, failed testing.

#37

Status:needs work» needs review

Yikes. Once again with the changes from #34.

AttachmentSizeStatusTest resultOperations
d8-tests-for-comment-deletion-890790-37.patch25.27 KBIdleFAILED: [[SimpleTest]]: [MySQL] Failed to run tests: failed during invocation of run-tests.sh.View details
interdiff.txt2.11 KBIgnored: Check issue status.NoneNone

#38

Status:needs review» needs work

The last submitted patch, d8-tests-for-comment-deletion-890790-37.patch, failed testing.

#39

Your last patch also reverted the CommentTestCase -> CommentTestBase change.

#40

Status:needs work» needs review

Crossing fingers...

AttachmentSizeStatusTest resultOperations
d8-tests-for-comment-deletion-890790-40.patch25.27 KBIdlePASSED: [[SimpleTest]]: [MySQL] 36,626 pass(es).View details
interdiff.txt2.11 KBIgnored: Check issue status.NoneNone

#41

Status:needs review» reviewed & tested by the community

Nice. Thanks for the help on this. It should be ready for catch again.

#42

Opened #1588284: Convert comment tests to PSR-0 to convert the rest of the comment tests to PSR-0.

#43

Assigned to:dags» Tor Arne Thune

Just removing an unneeded use statement.

AttachmentSizeStatusTest resultOperations
d8-tests-for-comment-deletion-890790-43.patch25.23 KBIdlePASSED: [[SimpleTest]]: [MySQL] 36,640 pass(es).View details
interdiff-890790-40-43.txt520 bytesIgnored: Check issue status.NoneNone

#44

Berdir pointed out that there is no need for use Drupal\comment\Tests\CommentTestBase; when we're in the same namespace, which of course makes sense.

AttachmentSizeStatusTest resultOperations
d8-tests-for-comment-deletion-890790-44.patch25.19 KBIdlePASSED: [[SimpleTest]]: [MySQL] 36,645 pass(es).View details
interdiff-890790-43-44.txt491 bytesIgnored: Check issue status.NoneNone

#45

Version:8.x-dev» 7.x-dev
Status:reviewed & tested by the community» patch (to be ported)
Issue tags:+Novice

Sorry I didn't think about CommentTestBase when asking for PSR-0-ification but thanks! Committed/pushed to 8.x, moving to 7.x for backport.

#46

Status:patch (to be ported)» needs review

Thanks. Learned a lot converting it to follow PSR-0, with the help of davidjdagino. The attached D7 patch is a re-roll of the RTBC patch in comment #16.

AttachmentSizeStatusTest resultOperations
D7-tests-for-comment-deletion-890790-46.patch1.16 KBIdlePASSED: [[SimpleTest]]: [MySQL] 39,106 pass(es).View details

#47

Status:needs review» reviewed & tested by the community

Setting this to RTBC as the identical patch in #16 was RTBCed in #17. The rest of the discussion is just about the PSR-0 conversion of the D8 version of the patch.

#48

Backport looks good to me.

#49

Status:reviewed & tested by the community» fixed

Committed to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/ecf40c6

#50

Title:(Tests needed) deleting nodes does not delete their comments.» deleting nodes does not delete their comments.
Assigned to:Tor Arne Thune» Anonymous
Issue tags:-Needs tests

#51

Priority:normal» critical

Setting back to original priority of this bug. (See #5.)

#52

Status:fixed» closed (fixed)

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