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.
Hi Brian, What happens if you bypass the static caching in node_load, by changing your node_load call to: $node = node_load($nid, NULL, TRUE); Does that change anything? Regards Steven Jones ComputerMinds ltd - Perfect Drupal Websites Phone : 024 7666 7277 Mobile : 07702 131 576 Twitter : darthsteven http://www.computerminds.co.uk On 23 July 2010 14:46, Brian Vuyk <brian@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.
Thanks for the suggestion. Unfortunately, that did not affect the behaviour. I did a few test runs with it, the first 2 returned proper results, the third run had all the problematic node_load()s again. It had my hopes up momentarily, though! Brian On 10-07-23 09:51 AM, Steven Jones wrote:
Hi Brian,
What happens if you bypass the static caching in node_load, by changing your node_load call to:
$node = node_load($nid, NULL, TRUE);
Does that change anything?
Regards Steven Jones ComputerMinds ltd - Perfect Drupal Websites
Phone : 024 7666 7277 Mobile : 07702 131 576 Twitter : darthsteven http://www.computerminds.co.uk
On 23 July 2010 14:46, Brian Vuyk<brian@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.
Disregard my earlier email then, sorry. Your test case isn't doing anything with the $context variable. I know it's best practice to use that array to tell batch API how far along it is -- I've never not done that, maybe that's part of the problem? If you make your test case look more like the batch api from the examples module, does that still repeat the same error? Justin On Fri, Jul 23, 2010 at 9:12 AM, Brian Vuyk <brian@brianvuyk.com> wrote:
Thanks for the suggestion.
Unfortunately, that did not affect the behaviour. I did a few test runs with it, the first 2 returned proper results, the third run had all the problematic node_load()s again.
It had my hopes up momentarily, though!
Brian
Steven - here is a screenshot of the dpm() output of one of the partially loaded nodes: http://i.imgur.com/7ig0B.png Note that the message at the bottom ('NID is 730') pulls that from the $nid argument passed to the function. Brian On 10-07-23 09:51 AM, Steven Jones wrote:
Hi Brian,
What happens if you bypass the static caching in node_load, by changing your node_load call to:
$node = node_load($nid, NULL, TRUE);
Does that change anything?
Regards Steven Jones ComputerMinds ltd - Perfect Drupal Websites
Phone : 024 7666 7277 Mobile : 07702 131 576 Twitter : darthsteven http://www.computerminds.co.uk
On 23 July 2010 14:46, Brian Vuyk<brian@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.
Any pattern to the uid of the affected nodes? Have you tried putting in a sleep() function to slow the processing down a little? Is there a row for uid 0 in your users table? There should be, but sometimes people remove it, not realizing it's a load-bearing zero. -- John Fiala www.jcfiala.net
John: It's either all nodes in a run of the batch process, or none of them. The script processes the exact same nodes every time I run it; and on an individiual run of the batch process, either all nodes load bad, or none of them do. Does that clarify? We haven't deleted the anonymous user. Brian On 10-07-23 10:47 AM, John Fiala wrote:
Any pattern to the uid of the affected nodes?
Have you tried putting in a sleep() function to slow the processing down a little?
Is there a row for uid 0 in your users table? There should be, but sometimes people remove it, not realizing it's a load-bearing zero.
What do you mean by batch script? Is it running in side or outside Drupal? Is it possible it's a permission problem or that you are running out of memory?
On 10-07-23 09:53 AM, Steve Ringwood wrote:
What do you mean by batch script? Is it running in side or outside Drupal? Is it possible it's a permission problem or that you are running out of memory? I mean a module utilizing the Batch API:
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@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.
participants (6)
-
Brian Vuyk -
Domenic Santangelo -
John Fiala -
Justin Ellison -
Steve Ringwood -
Steven Jones