Failure on node_load results in creation of a new empty node

MMachnik - November 10, 2009 - 18:49
Project:FeedAPI
Version:6.x-1.8
Component:Code feedapi_node
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Working on a client site that has several thousand feeds and several hundred thousand nodes. On many pages they were getting this warning:

warning: Invalid argument supplied for foreach() in .../sites/all/modules/cck/content.module on line 1284.

At first glance this may seem to be this issue: http://drupal.org/node/367111 -- however, I believe it is actually a separate issue.

There were several thousand nodes in the system that were almost completely empty -- blank content type, no title/body, etc. However, there was an entry in term_node for the nid and when a user viewed a page that contained a view that pulled that node, CCK was throwing the warning due to the node not having a type.

The problem is the creation of those virtually empty nodes. It is happening in the same section of code as the node_object_prepare() call, however it is the failure to successfully load a feed item node that is leading to this. Because it starts off with an empty node object rather than a valid one, it ends up creating a new node that is missing almost everything.

The code in question from _feedapi_node_save():

  // If there are dupes on other feeds, don't create new feed item, but link this feed
  // to existing feed item.
  // Heads up: if there is a duplicate on the SAME feed,
  // _feedapi_node_save() won't even be called.
  if (isset($feed_item->feedapi_node->duplicates)) {
    foreach ($feed_item->feedapi_node->duplicates as $fi_nid => $f_nids) {
      $feed_item_node = node_load($fi_nid);
      $feed_item_node->feedapi_node->feed_nids[$feed_nid] = $feed_nid;
      node_object_prepare($feed_item_node);
      node_save($feed_item_node);
    }
  }

If $feed_item_node is empty, it should not execute the next three lines.

As to why the node_load would fail -- a separate issue I am still investigating. It appears that in some cases there are nodes in the system that have an invalid vid -- one that does not exist in node_revisions. You cannot even load the page (node/NID), you get a 404, but the node does exist in the node table.

At any rate, I believe that the code above should check that it does have a valid node after calling node_load and doing anything with the object it gets back.

Thank you!

#1

Aron Novak - November 12, 2009 - 17:24
Status:active» needs review

Can you test this patch below?

AttachmentSize
628962_check_missing_node_on_dupe_handling.patch 1.08 KB
 
 

Drupal is a registered trademark of Dries Buytaert.