views:

221

answers:

4

Nodes of this certain types can be created by anonymous or registered users. If a registered user creates it, everything works fine. If an anon creates it, going to that node's page results in a 404 error.

The node clearly exists, however. If I edit its entry in the node table and set its uid to be something other than 0, everything works fine.

Why is this?

This rule holds throughout all node types, CCK generated and otherwise. If I set uid = 0, it breaks. If I set uid = 2 (or any other number not 0), it works fine.

debug_print_backtrace() results in this:

#0 drupal_not_found() called at [/home/sitename/public_html/sitename2/index.php:24]
+1  A: 

This is clearly the work of a custom/contrib module but it's impossible to guess the source.

It sounds like something is going on in an implementation of hook_nodeapi that asumes that the node creator isn't user 0. Having deleted user 0 from the user table might also cause bugs but not exactly like this.

A custom implementation of node/% either in a module or view could also be the root.

googletorp
I searched through every hook_nodeapi in the project and couldn't find anything offensive, at least in the code I wrote myself. debug posted above.
Rosarch
+1  A: 

I second googletorps assumption that this is most likely caused by some custom/contributed module.

You could pinpoint the offending code by temporarily putting $backtrace = debug_backtrace() at the top of the drupal_not_found() function in common.inc and inspect the result using a debugger. (Alternatively, you could use debug_print_backtrace() to simply print the trace instead of the Drupal 404 page.)

The trace will list the function calls (along with their arguments) that lead to the call of drupal_not_found().


Edit after question update (404 issued in index.php):

This is pretty weird/irritating, as it means that menu_execute_active_handler() could not determine a matching drupal menu/path entry (by calling menu_get_item() in turn). The path/menu determination logic should not depend on the node author at all (except maybe concerning access rights, but that should only lead to a 403, not 404).

So I have absolutely no idea on what might cause this :/

Have you tried turning off the contributed modules to see if this changes the behavior and maybe pinpoint an offender?

Henrik Opel
+1  A: 

I got the exact same error: user uid = 0 was missing from the users table...

the error was happening inside the node.module node_load() function, as you have a join query between node and users table

meh
I have this problem too! perhaps this is the cause. what data does the `uid = 0` row need to have?
Rosarch
beside uid = 0 nothing really... so you can try something like:INSERT INTO users SET uid = 0, name = 'anonymous'; if you are using roles don't forget to add this entry into the users_roles table:INSERT INTO users_roles VALUES(0,1);And don't forget to clean the cache...
meh
A: 

This is a few months old, so I'm sure you've figured something out by now. But, since I just came across the same problem, I'm posting this for the next person that comes looking for an answer:

Check that the users table has an entry for the anonymous user - that is, where the uid field is 0.

When loading a node to display, the node_load() function uses an INNER JOIN to join the node table to the users table. If node.uid is 0 and there is no matching user record with uid = 0, it returns an empty set.

I think I messed mine up when copying the DB from one server to another. I wasn't able to replicate it just now, but I know I've seen issues before where MySQL doesn't take kindly to a 0 in an auto_increment field. In this case, my anonymous user record was uid = 5, so I just changed it back to 0 and all was right with the world.

Brock Boland
Also, once correcting this, you may need to go back and clean up some items in the `node` table. In my case, a couple nodes had been created with the new (incorrect) anonymous uid of 5. Since there was no longer a user with a uid of 5, those nodes would no longer display, and I had to change the uid on those nodes back to 0.
Brock Boland

related questions