I observed this problem with D6 with cck build modes but realized that this problem exists with D7 as well. The issue is complicated and I have struggled with the right way to describe it, so here goes.

If we have a page view that does node_view() (say the /node) and we have a block that does node_view() but with a different build mode. The content array will be preserved for the block rendering, so all $node->content that was put there for node_view('teaser') will be there for node_view('block_build_mode').

This patch makes it so $node->content() is always rebuilt for each call to node_build_content(). Which makes sense semantically, calling node_build_content() means that we are building from scratch.

(marked as critical cause I really believe this is. I know most people don't have node_view() on the same node on the same page. I know node_loads() are bad for performance, but we should be able to handle this case).

Attached is a fix for D6 as well.

Comments

Scott Reynolds’s picture

moshe weitzman’s picture

Status: Needs review » Needs work

makes perfect sense. you can delete that $node->content = array() line and let $node->content = field_attach_view(). Slightly less verbose. after that, is rtbc.

Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new775 bytes

haha good call. Was running out the door for lunch...

Status: Needs review » Needs work

The last submitted patch failed testing.

moshe weitzman’s picture

Status: Needs work » Reviewed & tested by the community
moshe weitzman’s picture

Status: Reviewed & tested by the community » Needs work

Actually, comment_build_content() and user_build_content() suffer from the same bug. Could you patch those too? Terms do not have this problem.

moshe weitzman’s picture

Ewww. Failures in poll tests. Have fun with that :)

sime’s picture

Would it work to add 'rebuild' parameter to node_build_content? This could be TRUE by default, then modify poll module call to not rebuild it.

damien tournoud’s picture

Status: Needs work » Needs review
StatusFileSize
new1 KB

Let's test doing it this way.

damien tournoud’s picture

Issue tags: +Needs tests

We will need a small test for that.

moshe weitzman’s picture

Looks like right approach. Would love similar fix for user and comment

matt2000’s picture

Title: Preserving $node->content across multiple node views » Preserving $node->content and $comment->content across multiple node views
StatusFileSize
new1.72 KB

Doesn't look like user needs it, but this patch covers comment as well.

moshe weitzman’s picture

Indeed you are right. Users already zero our the content property when building.

Status: Needs review » Needs work

The last submitted patch failed testing.

matt2000’s picture

Status: Needs work » Needs review
StatusFileSize
new1.73 KB

chasing HEAD...

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

Version: 7.x-dev » 6.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed to HEAD. Thanks!

Sounds like this needed to be ported to D6 as well?

Scott Reynolds’s picture

Yes, it is a bug that exists in 6 as well, though a little more obscure as 6 Core doesn't have many build modes. Still a bug, and becomes apparent when using CCK build modes.

Also missing a test still right?

webchick’s picture

Version: 6.x-dev » 7.x-dev
Status: Patch (to be ported) » Needs work

D'oh. :) Yes.

Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new3.24 KB

As you have already committed the patch, here are two simple test for node and comment.

They follow the same structure, load the object, add something to content, then check for that something after a call to object_build().

matt2000’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. This test will confirm that the preceding patch has does it's job.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Awesome, thanks! Just some minor things.

+++ modules/comment/comment.test	3 Nov 2009 07:22:41 -0000
@@ -914,3 +914,35 @@ class CommentRdfaTestCase extends Commen
+  public function testCommentRebuild() {

This needs PHPDoc. Also, this doesn't need to be a public function. Just plain ol' function will do.

+++ modules/comment/comment.test	3 Nov 2009 07:22:41 -0000
@@ -914,3 +914,35 @@ class CommentRdfaTestCase extends Commen
+    $this->drupalLogin($this->admin_user);
+    $this->setCommentSubject(TRUE);
+    $this->setCommentPreview(DRUPAL_OPTIONAL);
+    $this->drupalLogout();
+    $this->drupalLogin($this->web_user);
+    $subject_text = $this->randomName();
+    $comment_text = $this->randomName();
+    $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
+    $comment_loaded = comment_load($comment->id);
+    $this->assertTrue($this->commentExists($comment), t('Comment found.'));
+    
+++ modules/node/node.test	3 Nov 2009 07:22:42 -0000
@@ -1070,3 +1070,26 @@ class NodeFeedTestCase extends DrupalWeb
+    $this->assertFalse(isset($content['test_content_property']), t('Node content was rebuilt'));

This is a lot of dense code. It'd be nice to break it up with an inline comment or two for easier scanning.

+++ modules/comment/comment.test	3 Nov 2009 07:22:41 -0000
@@ -914,3 +914,35 @@ class CommentRdfaTestCase extends Commen
+    // add the property to the content array and then see if it still exists on build
...
+    // this means that the content was rebuilt as the added test property no longer exists
+++ modules/node/node.test	3 Nov 2009 07:22:42 -0000
@@ -1070,3 +1070,26 @@ class NodeFeedTestCase extends DrupalWeb
+  * Create one node and add a piece to its content array. ensure that that piece doesn't remain
...
+    // set a property in the content array so we can test for its exsistance later on
...
+    // if the property doesn't exist it means the node->content was rebuilt

Comments should "Start with a capital, end with a period." Also, wrap at 80 chars.

+++ modules/node/node.test	3 Nov 2009 07:22:42 -0000
@@ -1070,3 +1070,26 @@ class NodeFeedTestCase extends DrupalWeb
+class NodeBuildContent extends DrupalWebTestCase {

PHPDoc.

+++ modules/node/node.test	3 Nov 2009 07:22:42 -0000
@@ -1070,3 +1070,26 @@ class NodeFeedTestCase extends DrupalWeb
+    $this->assertFalse(isset($content['test_content_property']), t('Node content was rebuilt'));

Same comment as the earlier one on the detail of assertion message.

I'm on crack. Are you, too?

Scott Reynolds’s picture

StatusFileSize
new3.14 KB

Ok heres a re-roll.

catch’s picture

Status: Needs work » Needs review
Scott Reynolds’s picture

StatusFileSize
new3.18 KB

Heres another reroll, with added periods for the test description, and better assertion messages.

catch’s picture

Priority: Critical » Normal
Status: Needs review » Reviewed & tested by the community

Looks good.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Scott Reynolds’s picture

As per Webchick #17, I think this bug can be fixed in D6 as well. I posted a patch on the node already.
http://drupal.org/files/issues/content-d6.patch

Scott Reynolds’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Needs review

forgot to change the Issue fields.

int’s picture

Version: 6.x-dev » 7.x-dev
Priority: Normal » Critical
Status: Needs review » Needs work

I think that this issue are breaking the testbot..

http://qa.drupal.org/pifr/test/32

catch’s picture

Title: Preserving $node->content and $comment->content across multiple node views » [Needs rollback] Preserving $node->content and $comment->content across multiple node views

Very, very odd that those tests passed in the queue but fail now, we should rollback then investigate.

dave reid’s picture

+++ modules/comment/comment.test
@@ -914,3 +914,42 @@ class CommentRdfaTestCase extends CommentHelperCase {
+    $built_content = comment_build($comment_loaded, $this->node);

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /batch?id=104&op=do StatusText: OK ResponseText: Fatal error: Call to undefined function comment_build() in /home/dave/Projects/www/drupal7dev/modules/comment/comment.test on line 1226 Call Stack: 0.0001 65992 1. {main}() /home/dave/Projects/www/drupal7dev/index.php:0 0.2395 17111692 2. menu_execute_active_handler() /home/dave/Projects/www/drupal7dev/index.php:22 0.2468 17933444 3. call_user_func_array() /home/dave/Projects/www/drupal7dev/includes/menu.inc:466 0.2468 17933712 4. system_batch_page() /home/dave/Projects/www/drupal7dev/includes/menu.inc:0 0.2468 17933812 5. _batch_page() /home/dave/Projects/www/drupal7dev/modules/system/system.admin.inc:2267 0.2469 17937624 6. _batch_do() /home/dave/Projects/www/drupal7dev/includes/batch.inc:81 0.2469 17937664 7. _batch_process() /home/dave/Projects/www/drupal7dev/includes/batch.inc:163 0.2483 18020240 8. call_user_func_array() /home/dave/Projects/www/drupal7dev/includes/batch.inc:286 0.2483 18020380 9. _simpletest_batch_operation() /home/dave/Projects/www/drupal7dev/includes/batch.inc:0 0.2586 19493852 10. DrupalTestCase->run() /home/dave/Projects/www/drupal7dev/modules/simpletest/simpletest.module:192 6.3158 28085352 11. CommentContentRebuild->testCommentRebuild() /home/dave/Projects/www/drupal7dev/modules/simpletest/drupal_web_test_case.php:442

There is no comment_build function in D7. Might be looking for comment_build_content()?

Powered by Dreditor.

Scott Reynolds’s picture

Comment build used to exist. Can't find where we changed it.

#523950: Update comment rendering ? I don't know whatever, working on fixing.

dave reid’s picture

Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new1.29 KB

Cool so here is the fix. Test didn't pass before, passes now.

And a comment was too long.

catch’s picture

comment_view should be comment_view(), otherwise looks great as long as testbot is happy.

dave reid’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.29 KB

Confirmed patch in #35 fixes the test failures. Fixed the documentation and RTBC'ing.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. That should fix the tests.

int’s picture

Title: [Needs rollback] Preserving $node->content and $comment->content across multiple node views » Preserving $node->content and $comment->content across multiple node views
Version: 7.x-dev » 6.x-dev
Priority: Critical » Normal
Status: Fixed » Needs work

and now, return to D6

Scott Reynolds’s picture

Status: Needs work » Needs review

Patch attached to the issue node.

Status: Needs review » Needs work

The last submitted patch, 564642_comment_rebuild_test.patch, failed testing.

Scott Reynolds’s picture

Status: Needs work » Patch (to be ported)

the poor testing bot is confused. Its not up for D7 its up for D6 review.

emdalton’s picture

Did this ever get fixed in D6? We have a bad apache memory leak I'm trying to track down.

alan d.’s picture

Err: I just come across this from #564632: Cruft in $page due to node_build, comment_build, etc.. A D8 patch is in that queue, but I will close it once the test bot has run.

Use-case: A node view references something that also renders nodes through the node system. One of these nodes is the parental container itself, meaning that the $node->content array is reset and the parents build information is rendered NULL. This leads to a fatal error:

Fatal error: Unsupported operand types in modules/node/node.module on line 1362

So this was my workaround.

  // To support recursive calls, save any existing build information.
  $existing_content = isset($node->content) ? $node->content : NULL;
  
  // Populate $node->content with a render() array.
  node_build_content($node, $view_mode, $langcode);
  $build = $node->content;

  // Reset $node->content with any existing build information.
  $node->content = $existing_content ;
 

A Drupal 7 patch is attached.

For D8: Note unlike that other comments, rather than rebuilding from scratch, I would suggest adding in the context of the view mode to the content array and not resetting. Thus caching a copy and enabling reuse rather than rebuilding each time it is required. Only common use-case would be on listings that allow duplicates, like events with multiple sessions, where the same listing can show multiple times.

[Edit] This is one of the reasons why calendars in Drupal always appear so slow :( [/Edit]

alan d.’s picture

Version: 6.x-dev » 7.x-dev
Status: Patch (to be ported) » Needs review
StatusFileSize
new832 bytes

I removed the white space before the semi-colon.

Status: Needs review » Needs work
Issue tags: -Needs tests
alan d.’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
xjm’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +Needs backport to D7

I'm a little confused by #44. We need to whatever bug still exists in D8 first, even if we come up with a better fix later. Also, let's get an automated test that demonstrates the functional bug.

alan d.’s picture

I think the easiest way would be to create a simple filter tag that renders a node teaser. Then enable this filter on a node body field. Edit a node and insert this tag with the nid of the node being edited. It is a really obscure bug!

I triggered it by embedding an insert_view tag into the content of a node. This showed a teaser listing of recently updated content. If the node that had this tag was rendered in this listing, the fatal error occurred. [Mind you there were bigger bugs to resolve in the insert_view module to even get this far - recursive rendering of the same view tag, I've posted a patch in that modules issue queue to prevent this.]

hefox’s picture

Issue summary: View changes

(#45 is working nicely for those that just need to fix it)

hefox’s picture

Does anyone know if d8 has this bug?

Got bitten by this again

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.

xtfer’s picture

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

I'm going to go out on a limb and suggest that this is not relevant for D8 because of the way it handles multiple builds within the entity controller.

xtfer’s picture

Title: Preserving $node->content and $comment->content across multiple node views » Preserve $node->content and $comment->content across multiple node views
Status: Needs work » Needs review
Issue tags: -Needs backport to D7
StatusFileSize
new1.15 KB

Rerolled #45 against 7.x-dev and queued for testing.

  • webchick committed 6afea0a on 8.3.x
    #564642 by Scott Reynolds, Damien Tournoud, matt2000, and moshe weitzman...
  • Dries committed 3fbe8b7 on 8.3.x
    - Patch #564642 by Scott Reynolds: added tests for node_rebuild() and...
  • Dries committed fa4cfd6 on 8.3.x
    - Patch #564642 by Scott Reynolds, Dave Reid: comment_build() was...

  • webchick committed 6afea0a on 8.3.x
    #564642 by Scott Reynolds, Damien Tournoud, matt2000, and moshe weitzman...
  • Dries committed 3fbe8b7 on 8.3.x
    - Patch #564642 by Scott Reynolds: added tests for node_rebuild() and...
  • Dries committed fa4cfd6 on 8.3.x
    - Patch #564642 by Scott Reynolds, Dave Reid: comment_build() was...
donquixote’s picture

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC - though I think we really should write a test for it, so I probably will need to put it to CNW next when I review the RTBC queue with my maintainer head on ;).

I just want to signal that I think that this is ready.

The last submitted patch, content-d6.patch, failed testing.

fabianx’s picture

Status: Reviewed & tested by the community » Needs work

We indeed will need a test for this, setting to Needs work for that.

  • webchick committed 6afea0a on 8.4.x
    #564642 by Scott Reynolds, Damien Tournoud, matt2000, and moshe weitzman...
  • Dries committed 3fbe8b7 on 8.4.x
    - Patch #564642 by Scott Reynolds: added tests for node_rebuild() and...
  • Dries committed fa4cfd6 on 8.4.x
    - Patch #564642 by Scott Reynolds, Dave Reid: comment_build() was...

  • webchick committed 6afea0a on 8.4.x
    #564642 by Scott Reynolds, Damien Tournoud, matt2000, and moshe weitzman...
  • Dries committed 3fbe8b7 on 8.4.x
    - Patch #564642 by Scott Reynolds: added tests for node_rebuild() and...
  • Dries committed fa4cfd6 on 8.4.x
    - Patch #564642 by Scott Reynolds, Dave Reid: comment_build() was...

  • webchick committed 6afea0a on 9.1.x
    #564642 by Scott Reynolds, Damien Tournoud, matt2000, and moshe weitzman...
  • Dries committed 3fbe8b7 on 9.1.x
    - Patch #564642 by Scott Reynolds: added tests for node_rebuild() and...
  • Dries committed fa4cfd6 on 9.1.x
    - Patch #564642 by Scott Reynolds, Dave Reid: comment_build() was...

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.