Deleted username but can not use that username in other user

AI-generated summary

A user, pablogg, deleted a user with a certain username but is unable to reuse the same username for another user, receiving the message “Username has to be unique.” Canapin suggests checking if the username is taken or not completely deleted using the admin panel or the Data Explorer plugin.

After attempting these methods and finding no results, Canapin shares the code that checks if a username is already taken, which includes a check for both users and groups. He speculates that the issue might be due to a reserved username or a group with the same name.

codinghorror also suggests that the issue could be due to a group with the same name, as users and groups share a namespace. However, pablogg confirms that there is no group with the same name. Additionally, pablogg notes that they can still mention the deleted username in direct messages.

I have deleted a user with username = “XXX” and I want yo change the username of other user with the same username of deleted user but I can not. I get the mensagges. “Username have to be unique”

How can I check if a username is taken or not complete deleted?

Regards

You can go in your admin → users → filter by username.
Alternatively, you could use data explorer.

Yes, I have deleted the user from admin–>users but After that I can not use the same username that I removed

Then try using data-explorer and execute this request:

SELECT username FROM users WHERE username LIKE '%username%' 

Might give some clue.

No results. But when I try to use the username of a user deleted I get the messages that username must be unique.

Other table where can be that username?

I don’t know. What is the username you’re trying to use?
Maybe you try a reserved username, but I guess you’d have a different message…
Also the previous user woudn’t have been able to choose it :man_shrugging:t6:

Here’s the code that checks if a username is already taken:

  USERNAME_EXISTS_SQL = <<~SQL
    (SELECT users.id AS id, true as is_user FROM users
    WHERE users.username_lower = :username)

    UNION ALL

    (SELECT groups.id, false as is_user FROM groups
    WHERE lower(groups.name) = :username)
  SQL

Any deleted user?

edit: I tried to rename a user the same name as a group, and it says the username must be unique. Maybe that’s your issue?

Do you have a group with this name? @Canapin is correct that users and groups share a namespace.

No, I have not any group with the same name.

Another thing is that I can mention in DM messages username of deleted users.