I have a CCK type "Assembly" which has a field of type Computed Field. When I edit a node via the node edit web form, then click "Save", the computed field gets computed and stored in the DB. That works fine.

The problem is when I try calling node_save($node) outside of the context of the node update form.

When I call node_save($node) on an assembly node, the Computed Field gets computed. I have verified that by instrumenting the PHP that computes the field. But the computed field does not get stored in the DB. I can verify that by accessing the web page for the node. If I then click "Edit" and then immediately click "Save", the computed field does get stored in the DB.

Inside the php for computing the field, I printed the debug_backtrace(). Here is the backtrace I get when clicking on "Save" on the edit webform (outermost call first):

menu_execute_active_handler;
call_user_func_array;
node_page_edit;
drupal_get_form;
drupal_process_form;
form_execute_handlers;
node_form_submit;
node_save;
node_invoke_nodeapi;
content_nodeapi;
content_update;
_content_field_invoke;
computed_field_field;
_computed_field_compute_value;
computed_field_field_assembly_bom_args_compute;

That last function is my function for generating the computed field, and it is where I print out the stack. Here is the backtrace I get when calling node_save($node):

node_save;
node_invoke_nodeapi;
content_nodeapi;
content_update;
_content_field_invoke;
computed_field_field;
_computed_field_compute_value;
computed_field_field_assembly_bom_args_compute;

In other words, from node_save() on down, the chain of calls is the same.

Why doesn't node_save($node) save the computed field to the DB the way clicking "Save" on the webform does?

Comments

bobmct’s picture

I'll add a bump to this non-answered question.

I too am experiencing issues with node_save NOT storing one or more fields. I've verified immediately before the call to node_save that the node fields have the content desired. But like you, checking the node content AFTER the node_save, the value in question is NOT there. Makes importing content quite difficult, doesn't it?

Hopefully someone will have a response to point us in the correct direction. Thanks.

JoshuaKissoon’s picture

hey, can u put part of the code on how u set the value into the node object? i really cant help you from the info u got there