In installed and uninstalled a module that was causing problems that maintainer could not reproduce. That module is privatemsg. There's no trace of that module on my system now : no tables, no folder. I disabled it before deleting the 3 tables and deleting the files as well.
Now I am getting these errors :
warning: Invalid argument supplied for foreach() in /.../modules/node.module on line 376.
warning: implode() [function.implode]: Bad arguments. in /.../modules/node.module on line 380.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /.../includes/database.mysql.inc on line 121.
When I am getting these errors :
Pretty much anytime : pressing home, pressing track, pressing edit, from anywhere.
I have a MySQL database.
This issues has popped out for serveral other people :
http://drupal.org/node/63500
http://drupal.org/node/77601 (this is assigned to some module but it's not clear that this module has anything to do with this).
Comments
Comment #1
Chill35 commentedComment #2
webchickStep 1: Try and reproduce on a totally clean install. I'm assuming this won't work, or else this bug should be much more widely reported. If you can, we need lots of details like what versions of PHP, MySQL, Apache, etc. you're running.
Step 2: Disable all contributed/custom modules and themes on the site that's exhibiting the behaviour and see if you can reproduce. If you can't, then enable things one by one until the problem resurfaces, and file a bug against the appropriate module. If you can, then see if one of the modules you're running required a change to node.module or something?
One other thing to note is that http://drupal.org/node/63500 and http://drupal.org/node/77601 are not reporting the same thing as this bug... while the "Invalid argument supplied for foreach()" stuff is the same, the line numbers are different, so that means they're referring to separate chunks of code.
Comment #3
Chill35 commentedI assumed that if the line numbers differed by a couple of lines, it was because it was a different version of drupal 4.7.
I am very sick now, so I don't have much time to check now if these issues are similar but I am 95% sure they are.
I did as you suggested, I had a fresh install and enabled the contributed modules one by one.
The problem was with one of my own modules.
I was calling node_load() with an undefined argument. This was called whenever there was a user picture on the page. In details, here is what was happening :
1. When there is a user picture on the page, the hook function hook_file_download() is called for all modules, because these pictures are uploaded using the upload module.
2. In my module, I was using that hook function, and in it I was invoking node_load to find the node to which the downloaded file was attached - forgetting that downloaded files are not always attached to nodes.
This being said, I think that this function is not well-written :
It accepts that there are no arguments sent, but can't deal with an empty $param array.
In the cases where node_load is called with an undefined argument, a more meaningful error message should be set. Or, alternatively, this should be added at the beginning of the function :
By adding this code, with the comment uncommented, I was able to see what was going on.
Comment #4
Chill35 commentedImagine that, webchick, I was getting these errors whenever I was on OR leaving a page with a user picture on it. It didn't occur to me that it was a user picture causing this, it seemed random to me. LOL..
Comment #5
webchickWow, nice sleuthing! :) I'm very impressed!
Not sure how to take it from here... it seems like at the very least a clarification to the docs for node_load should be made... I don't really like the idea of drupal_set_message()ing a developer error though; users will see that stuff. Hmmm.
Comment #6
Chill35 commentedActually, there shouldn't be a message set, imo. Just a return false. That message I used only for debug reasons. I really am a newbie with Drupal, and don't know how to debug it. The way that function is defined, it should handle being called with an undefined argument. If the argument is undefined, then the function should no nothing. It'd be good to return false, just to known that no node was loaded, of couse. As it is, with an undefined argument, the function does 'free games'.
Comment #7
Chill35 commentedI should have copied and pasted.
The code I used to catch my own error was :
No "empty" function used here.
node.module declares the function node_load like this :
function node_load($param = array(), $revision = NULL, $reset = NULL) {The function can take as first argument either a single value (the nid) or an array of node info. As the comment says : . The function does a first check : is $param a numeric value ? Then it's an nid. If not, the function assumes it's an array.
If node_load is called with no argument, that is, someone write node_load(), then the function gets an empty array as default argument. It can't get any node, because there are no conditions.
Now if someone makes a mistake and call that function with an undefined argument (as I did), then the only improvement that can be made to that function is to include the code above. I am not sure it's a great idea though. It is actually a mistake on the part of the caller.
If Drupal functions were all checking for validity of arguments passed, then I guess a lot of Drupal code would need to be modified. It's like the php compliant stuff : it would require a lot of work. :)
Best regards,
Caro
http://www.11heavens.com
Comment #8
pasqualleThis version is not supported. Reopen or create a new issue if the problem exists in any recent version (version equal or above Drupal 5)