When you do an initial node creating using a drupal_execute (or node_submit - it really didn't matter if I did a node_submit or drupal_execute, but I ended up doing a drupal_execute - see my blog entry referenced at the bottom), nodeapi 'insert' operations get fired and from there contrib modules can do anything. If the contrib then does a node_load of the node being inserted, the CCK nodereference data (and possibly some other data) gets messed up and is never inserted.

I'm not sure, and hoping some CCK expert can trace this down further, that the node_load fires the nodeapi 'load' operation while the nodeapi 'insert' operation is still in progress and that CCK might have some hanging information about the node from the 'insert' operation that gets overwritten by the load operation. It's this information that I'm trying to insert that gets lost?

This took me quite a while to track down. Since I have a work-around (don't do node_load, or anything that calls node_load in nodeapi 'insert' operation), I won't be diving into this further. But maybe it will help others.

See also #185376,programmatically Create, Insert, and Update CCK Node Types, and source (drupal_execute in _uscongress_thomas_add_bill_node function).

Comments

Owen Barton’s picture

see also http://drupal.org/node/183649 (and it's friend http://drupal.org/node/183649) - I think this is related

douggreen’s picture

Summarizing from the above referenced thread and my experience:

Don't do recursive node_load() within hook_nodeapi view or insert operation, on nodes that have an imagefield or nodereference CCK field.

KarenS’s picture

Status: Active » Closed (duplicate)

This is probably the bug in [#Probably related to the drupal_execute() problem at #128038: Critical failures using drupal_execute() on nodes with CCK fields].