I was testing a forum thing, so I set it up to generate a bunch of forum nodes, and got a whole bunch of this error, one for each node:

"Notice: Undefined property: stdClass::$nid in forum_node_presave() (line 345 of /var/www/drupal7/modules/forum/forum.module)."

The problem, basically, is that when you create a node via a form, and it makes it's way through node_save(), the $node->nid exists on the object, and is NULL. But when devel_generate_content_add_node calls node_save(), the $node->nid does not exist on the object.

Comments

moshe weitzman’s picture

Status: Active » Fixed

committed the fix. thanks.

mgifford’s picture

Any idea when the next stable release will be out? I ran into this error too.

Status: Fixed » Closed (fixed)

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

nicholasthompson’s picture

It's also worth noting (if anyone stumbles on this in the future) that if you create a node using SimpleTest's drupalCreateNode function, you need to pass a NULL nid item in the array... eg:

    //Create a basic forum topic node
    $forum_node = array(
      'nid' => NULL,
      'type' => 'forum',
      'title' => 'Test Forum Node',
      'taxonomy_forums' => array('und' => array(0 => array('tid' => 1))),
    );  

    // Save the node
    $forum_node = $this->drupalCreateNode($forum_node);

If you don't then you run into the same issue described above.

The Forum module's test doesn't expose this as it posts to the "node/add/forum/1" page.

(sorry for dragging an old issue back up - but I found this through Google for a different problem caused by the same issue)

EDIT: Maybe there should be an isset() test before that query?

darksnow’s picture

I should apologise for bringing this up again too, but I've run into it during a migration I'm working on.

In pre_save, there is no nid, so I'd second the motion for an isset() call.

This looks similar to an issue in profile http://drupal.org/node/777168