I was having a problem with intermittent disappearance of a block on a site and I traced it back to what appears to be a bug in nodequeue_load_random_node().
After some digging, I determined that the failure was happening when nodequeue_load_random_node calls nodequeue_load_nodes and the rand call comes up with 1 - so the ultimate query ends up with LIMIT 1,1 - which gets you nothing if the total result set only has 1 record.
Looking at the rand() call, rand(0, $count - 1), the result should always be zero if $count is 1. But it turned out that in my case, $count was 2 even though there was only one item in the queue. I went into the db and confirmed that `nodequeue_nodes` did indeed contain only one nid for the sqid in question. When count is 2, rand(0, $count - 1) will randomly return 1, leading to the query LIMIT failure described above.
So that's where I stopped digging and implemented a workaround in my block code to check if there's only one node in the queue before using the nodequeue_load_random_node function. The root problem appears to be somewhere in the count query on line 2420
$count = db_result(db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {nodequeue_nodes} nn ON n.nid = nn.nid WHERE nn.sqid = %d AND n.status = 1"), $sqid));
This count is coming back 2 even though there's actually only one node in the queue.
Thanks!
G
Comments
Comment #1
amateescu commentedAre you using a module that implements node_access? If so, what is your Drupal version?
Comment #2
amateescu commentedPlease feel free to reopen if you can provide some more info.