Missing Anonymous User

I've spent the last few days wrestling with an evil bug. I had a content type, called Card, which I could create fine when logged in as any authenticated user of any role. All cool. I should also be able to create this content as anonymous.

Indeed, going to Create Card (node/add/card) was fine. I got the form, filled it in, but then nothing. Page Not Found where the created node was expected. The node simply wasn't created! But there were no warnings or errors. Big fat nada.

Past experience dictated I'd done something stupid in my custom module, which wasn't entirely impossible, as I was trying to redirect somewhere odd after node creation. And so the hoop-jumping began. Check permissions, rebuild permissions, uninstall custom module, re-install, start deleting variables, uninstall a few other modules, and so on and so on. *NOTHING* worked. Eventually I figured it actually wasn't me (shock, horror) and something more sinister was going on.

So by now clumps of my hair are on the office floor and I have no clue what the problem is. Enter our knight in shining armour, Alan Palazzo. Alan saw my desperate tweet and replied thus:

might have something to do with a node access module. Your anonymous user may have been deleted.

So I checked the users table and sure enough, the user ID for Anonymous had somehow changed to 4 (it should be 0). Do not ask me how this happened. I seriously have *no* idea.

But it's a good thing to know. If you start getting weird behaviour for the anonymous user, particularly around posting content, check the users table in Drupal. It could well be your Anonymous user account has gone AWOL. If the "zero" row is missing, or looks wrong compared to another installation, then restore it. It might well save you a lot of pain.

It's on my "to check" list from now on, if I ever experience similar issues again!

I am so happy that I found

I am so happy that I found this post.

It has been very helpful.. actually I was trying from days together to figure out page not found error..

Thank you

Same problem caused node_load to return false

I'd run into this problem before after moving my Drupal installation from my localhost to a live server. It manifested itself in a new way this time, which I thought I'd share for the benefit of desperately Googling Drupalistas.

This time, I used phpMyAdmin to make a copy of my database. Some nodes suddenly showed up as missing. After some debugging, I found that node_load was returning FALSE for those nodes, even though they showed up just fine in the database.

I went to my users table in phpMyAdmin and sure enough, the uid for the anonymous user had been changed from 0 to whatever the next available uid was. I changed it back to 0. Problem solved.

As Garrett and Nick point out above, this is a MySQL issue that can be avoided by taking care while copying or moving your database.

So glad I found this post!

I thought I was starting to go mad! I have one content type that I wanted anon users to be able to add (using for classified ads) and it used to work but following migration to another server it stopped working. I rebuilt permissions, cleared caches, disabled modules, pulled hair out many times! I came across this and I quickly discovered that I was missing user 0. With help of NO_AUTO_VALUE_ON_ZERO in mysql, I quickly sorted it out.

According to mysql documentation, they suggest against starting auto inc columns with a zero....

Now... on with the rest of my site, it's taken two days to trace this problem

I've had this happen on a

I've had this happen on a project before: the second most important Drupal user. There are many efforts in preventing deletion of uid 1, but a missing uid 0 can be just as devastating, and it's usually harder to debug when it hasn't happened to you before.

I'll join the choir; I've

I'll join the choir; I've been bitten by this issue before, and the problem seemed to have been brought about by MySQL trying to do too much when importing a database dump. So it's not so much a Drupal or PHP issue as it is a MySQL one. Bring on Drupal 7 and SQLite!

I have been bitten in the

I have been bitten in the past by the problem of Anonymous user not being uid = 0.
A lot of Drupal code is based on this assumption and not being so can break a lot of things.
The cause of the uid change is most likely an export/import of the SQL db. As the users table as the uid column set to auto_increment and uid = 0 is not a valid value (or so it seems), when re-importing the db the uid = 0 will end up having the max uid plus one.
Ping me at @flevour on Twitter!
Keep up the good work,
Francesco

This happens alot if you

This happens alot if you export your database and import it again while not having set the following value!

SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO

What this do is find 0 values and auto fills them with a 'valid' value, as in the next UID ID he can create.

For me, this explained how the mystery started :-)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.