Will assigning a name string to user #0 do any harm? By default, the {users}.name set for the Anonymous "user" (i.e. uid=0) is "" (empty) in Drupal 7.

This design choice is inconvenient for me in a module I'm maintaining (see issue #2099123 for background).

For instance, I need "Anonymous" to be available when there is an autocomplete form field that accepts a user name. Also, when I print out lists of users stored as serialized data in blobs, I want "Anonymous" to appear if there is a uid=0 somewhere in the list.

I've tried to use hook_username_alter(), but it has no impact on autocomplete widgets or serialized data.

I've looked for an API function to change the {users}.name field, and not found it.  I know there is a Drupal rule of thumb that say that updating another module's tables directly (i.e. without going through that module's API) is bad.

However, the solution I currently favour is to add a form to the admin interface that when clicked, does the following if the name field for uid=0 is "". (It does nothing if this field is not empty.)

$query = db_update('users')
  -&gt;fields(array(
    'name' =&gt; 'Anonymous',
  ))
  -&gt;condition('uid', 0)
  -&gt;execute();


I've tested this solution, and it solves the problem.

I've verified that leaving the author field empty to assign node ownership to user #0 (as suggested by the the hint "Leave blank for Anonymous.") still works after this database update.

I understand that the value of {variable}.anonymous may not be "Anonymous", but believe I can live with that.

Question 1: Will assigning a string value to this particular field if it is empty have potential to break something on a site that installs my module?

Question 2: Is there a more Drupalishly right way to do this? (I.e. a way where I do not have to interfere with a piece of data that rightfully belongs to the user module.)
For the record: I've done it.  One issue immediately popped up during testing: If a user named "Anonymous" already existed, creation would fail (obviously).  After modifying the routine to check for existing users before updating, it worked.

Been running on several production sites for a week, and no problems so far. I'll report here if any problems occur.