Critical Error: changed username, user got broken

I just changed the username of a person xxx on their demand. they wanted to take an inactive username yyy. so first I changed the inactive username yyy to somthing else like yyy1 and then changed that person username from xxx to yyy.
at this point, first, the user couldnt post anything and I saw the following error in the logs:

Job exception: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_username_lower" DETAIL: Key (username_lower)=(mina) already exists. 

I tried to change back the username to what was before, now all of their history is gone. What exactly did go wrong here?

1 Like

Can you repro this @tshenry?

2 Likes

Now I cant even open their profile page. Is there somthing I can do to heal this in the meantime?

1 Like

I’m working on going through the steps you outlined right now. I’ll let you know what I find.

5 Likes

btw idk why im getting error on this user (username_lower)=(mina) at all. I have never done any change to it and seems it is an inactive user. However I see a wierd behaviour on their profile too. If I open their notification page, I get a 404 error.

1 Like

Ok, I ran through the steps. If I did anything different from what you did, let me know.

There are two users:

  • xxx (active account)
  • yyy (inactive account)
  1. Change yyy to yyy1
    Change xxx to yyy
    ( :white_check_mark: worked for me)

  2. Try posting using the new yyy account
    ( :white_check_mark: worked for me)

  3. Change yyy back to xxx
    ( :white_check_mark: worked for me, no loss of user history)

I didn’t have any issues through the whole process. One thing to note is that after you change a user’s username from the user admin page, you will need to refresh the page before the “Show public profile” button will navigate to the correct user.

Can you check your /admin/logs/staff_action_logs to see if all of the logged username changes make sense? Clicking on the avatars of the listed usernames should take you to their current and correct user page.

4 Likes

Yes clicking on the avatar takes me to their page. however, it sems to me that their page is kind of inactive. for example I cant display their email or impersonate their account:

this is what I did so far:

according to what I see in this report, first I changed fatemeh to fatemeh12 . then changed fatemeh_baghdadi to fatemeh . after a while, the user told me that they cant post anything. so I thought maybe there was somthing wrong in the process of changing username and tried to change the username to somthing that hasnt been used so far. so I changed fatemeh (previously fatemeh_baghdadi) to fatemeh74. then I saw that their history got cleared totaly and I got nervous. So I tried to change back the username to what was in the begining from fatemeh74 to fatemeh_baghdadi . and again from fatemeh_baghdadi to fatemeh_baghdadi5 but nothing get better. now I have two diffrent user fatemeh74 and fatemeh_baghdadi5 which theoritically should be one person but actually they are 2 person, one seems to be not working correctly.

1 Like

I’m trying my best to follow along here. It sounds like a very odd situation!

Can you clarify what you mean when you say that their history was totally cleared? Should fatemeh_baghdadi5 have various topics and replies listed under the activity section of their profile?

If that is the case, are those posts now associated with the fatemeh74 account? They should exist somewhere on the site and be associated with a specific user. From an anonymous user perspective, I’m not able to find a user with the username fatemeh74 on your site.

There is a background job called EnsureDbConsistency that runs every 12 hours. It might be interesting to either trigger it manually from sidekiq, or wait and see if everything gets fixed automatically in the next 12 hours.

If you do end up having two accounts that should be one, you should be able to merge them. I would definitely take a backup before attempting that, however.

It’s really hard to understand what’s going on without having direct access to everything, but hopefully we can get it figured out!

2 Likes

at the moment that I changed the username, I went to their profile and saw no posts, etc. but it got fixed after a while. however now fatemeh74 which actually seems to be the correct person, is kind of inactive. I mean as you see, we cant see their profile page, while their post and other things are present. like this:

They are not actually one, I checked their email and their id and theyre completely diffrent. However according to the steps I changed the usernames, they should be the same and actually I shouldnt have two users here.

where is this exactly?

1 Like

Thanks for posting that example. That’s definitely concerning.

You can find it listed at /sidekiq/scheduler. It’s worth a shot, but based on what you just posted, it sounds like there might be a deeper issue.

2 Likes

Unfortunately you are right. It didnt fix my problem.

1 Like

@tshenry Is it ok that I can have two username that are exactly the same except for the first word which are uppercase/lowercase?

I think this might be related to the problem.

2 Likes

That’s an interesting observation!

Usernames are effectively case-insensitive, so you shouldn’t be able to have two users with the same username. However:

54%20PM

You can see what appears to be two distinct usernames returned when searching for fatemeh12. This shouldn’t have been able to happen (I’m not able to reproduce it). Both go to the same profile it seems.

I’m at a loss on where to go from here. If someone doesn’t chime in by around this time tomorrow, I’ll see if I can track someone down with some fresh ideas. If you find any additional information that you think is relevant in the mean time, please post it.

3 Likes

What I underestand by now is this: At the very first step, I tried to change fatemeh to fatemeh12 in order to make that username free. However, there was already a Fatemeh12 username, so in fact I shouldnt be allowed to change fatemeh to fatemeh12. However it weirdly let me do that and somehow database screwed from this point.

2 Likes

@tshenry did you find anything? right now the user fatemeh74 which was gone, is somehow healed. idk how exactly though. I want to make sure this wont happen in future, so I need to know why I have same usernames with uppercase/lowercase difference. and why discourse wont prevent such thing. my discourse is updated already .

4 Likes

Hey there :wave: That is great to hear. I was hoping that a background job might come to rescue after some time passed. It sounds like that might have been what happened.

I have not had a chance to look into this further. We are really limited on what we can do to help since we do not have database access to your site and would only be able to dig in like that for our hosted customers.

This is the first occurrence that we have heard of this happening and I’m not able to reproduce the behavior. I suspect this is an edge case with your instance. We will certainly keep an eye out for any similar occurrences in the future. If you want to be extra careful, I would just do a double check that there isn’t anyone with the same username before making a username change.

3 Likes

I’m OK with sending a copy of my database, if that might help finding the problem.

1 Like

I didn’t do anything but the user got broken again :expressionless: . There is defenately somthing wrong with my database.

1 Like

We are also experiencing this same issue for a long time now - of course there’s no way to reproduce how the database got in this state but every so often we end up with users either self-renaming to duplicate names during the rename grace period, but this also applies to admin renames.

We don’t use unicode usernames, and this is pretty… problematic at times as this breaks the Patreon plugin’s sync job at times which we heavily rely on for external policy services.

2 Likes