When exporting a node in hook_node_update, old data is being exported. Since the hook is executed before the static cache of node_load is cleared and node_export uses node_load without the reset parameter, old data is used.

Consider following code.

function hook_node_update($node) {
  $data = node_export($node);
  // ...
}

Code from node_save. The hook is called before the cache is cleared.

module_invoke_all('node_' . $op, $node);
module_invoke_all('entity_' . $op, $node, 'node');

// Update the node access table for this node. There's no need to delete
// existing records if the node is new.
$delete = $op == 'update';
node_access_acquire_grants($node, $delete);

// Clear internal properties.
unset($node->is_new);
unset($node->original);
// Clear the static loading cache.
entity_get_controller('node')->resetCache(array($node->nid));

Code from node_export. The node is loaded using node_load without the reset parameter.

$nodes = array();
  foreach ($nids as $nid) {
    $original_node = node_load($nid);

Possible solutions

Always request a fresh node by passing TRUE as the reset parameter for node_load.
Downside: performance when exporting a large number of nodes.
or
Introduce an optional reset parameter in node_export function that is passed to node_load.
Downside: more parameters.

Comments

Bart Vanhoutte’s picture

Issue summary: View changes

Clarified solution 1

  • danielb committed 71326b8 on 7.x-3.x
    Issue #2072449: Old data used when exporting in hook_node_update
    
danielb’s picture

I've just gone ahead and added a $reset param to anywhere that might need it if called by a developer.

danielb’s picture

Status: Active » Closed (fixed)