[development] node_load() oddness

Justin Ellison justin at techadvise.com
Fri Jul 23 14:12:42 UTC 2010


Try sticking this in your function:

static $nodecount = 0;
$node = node_load($nid);
$nodecount++;
if ($nodecount % 50 == 0) {
  node_load(NULL,NULL,TRUE);
}


On Fri, Jul 23, 2010 at 8:46 AM, Brian Vuyk <brian at brianvuyk.com> wrote:

> Can anyone think of a situation where a node_load() contained in a function
> returns partial results when the function is called from a batch script?
>
> I have a simple function that I am calling the from a batch API script that
> processes through a bunch of nodes to fix filepaths in certain migrated
> content. I've begun experiencing a strange issue while testing it; I've
> boiled it down to the following test case:
>
> <?php
>
> function migration_fix_photos($nid) {
>  $node = node_load($nid);
>  dpm($node);
>  drupal_set_message('NID is ' . $nid);
> }
> ?>
>
> When I call this function with a given NID from a batch script, on some
> runs, the $node object returned by $node_load is only partially loaded - it
> has 3 of the 10-12 CCK fields the node should contain, also, $node->title,
> $node->nid, $node->uid and $node->type are missing from the object, among
> other portions.
>
> The behavior changes between runs of the batch script. I can run a testing
> run, and only get partially loaded nodes. I can re-run the batch script, and
> they are fully loaded. Note that this changes per-run of the batch script,
> not per-call of the function. That is, when the batch script operates on
> 2000 nodes, the partial node_load() will or will not happen for all 2000
> times the above function is run. I could run the batch script again, and get
> perfectly normal results for all 2000 nodes next time.
>
> If I call the above function directly, it shows correct results every time.
> This only happens when called from a batch script. Note that the $nid
> argument is always shown as correct (tested with the drupal_set_message()
> call).
>
> Does anyone have any ideas why this is happening? I have tried using
> Xdebug, but I can't determine how to attach onto the background AJAX
>  requests the browser is making.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100723/2cb288e8/attachment.html 


More information about the development mailing list