# Critical Error: changed username, user got broken

**URL:** https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659
**Category:** Support
**Created:** [November 5, 2019, 2:32pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659 "2019-11-05T14:32:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 5, 2019, 2:32pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/1 "2019-11-05T14:32:26Z")

</div>

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:

```plaintext
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?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [November 5, 2019, 7:00pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/2 "2019-11-05T19:00:08Z")

</div>

Can you repro this @tshenry?

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 5, 2019, 7:15pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/4 "2019-11-05T19:15:58Z")

</div>

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

 ![Screenshot%20from%202019-11-05%2022-48-23](https://global.discourse-cdn.com/meta/original/3X/e/1/e18ab7997df4b7dd0bb3912b63a3ea08e875c503.png)

 ![Screenshot%20from%202019-11-05%2022-45-16](https://global.discourse-cdn.com/meta/original/3X/0/6/06e55dcb3de18186a4227f52000aa5cbc3a2d33a.png)

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [November 5, 2019, 7:18pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/5 "2019-11-05T19:18:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 5, 2019, 7:39pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/6 "2019-11-05T19:39:43Z")

</div>

> [@hosna](#):
>
> Job exception: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint “index\_users\_on\_username\_lower” DETAIL: Key (username\_lower)=(mina) already exists.

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.

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [November 5, 2019, 8:14pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/7 "2019-11-05T20:14:08Z")

</div>

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`  
( ✅ worked for me)

2. Try posting using the new `yyy` account  
( ✅ worked for me)

3. Change `yyy` back to `xxx`  
( ✅ 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.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 5, 2019, 8:33pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/8 "2019-11-05T20:33:40Z")

</div>

> [@tshenry](#):
>
> Clicking on the avatars of the listed usernames should take you to their current and correct user page.

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:

 ![Screenshot%20from%202019-11-05%2023-55-48](https://global.discourse-cdn.com/meta/original/3X/1/6/16f31e35b15066c08954dd4a73b58df935d483f0.png)

this is what I did so far:

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/f/2f6622f31fb9e302ab3b06e993fa2042d68ba552.png)

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.

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [November 5, 2019, 9:14pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/9 "2019-11-05T21:14:18Z")

</div>

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](https://meta.discourse.org/t/rake-task-for-merging-users/89086). 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!

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 5, 2019, 9:25pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/10 "2019-11-05T21:25:50Z")

</div>

> [@tshenry](#):
>
> Can you clarify what you mean when you say that their history was totally cleared?

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:

> **[معنی این جمله لطفا](https://talk.zabanshenas.com/t/topic/29066/3?u=hnaseri)**
>
> کلی نباید بگید جز به جز توضیح بدید دوستان متوجه شن آرمینا 🤣

> [@tshenry](#):
>
> If you do end up having two accounts that should be one, you should be able to [merge them](https://meta.discourse.org/t/rake-task-for-merging-users/89086).

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.

> [@tshenry](#):
>
> There is a background job called `EnsureDbConsistency` that runs every 12 hours. It might be interesting to either trigger it manually from sidekiq

where is this exactly?

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [November 5, 2019, 9:36pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/11 "2019-11-05T21:36:49Z")

</div>

> [@hosna](#):
>
> I mean as you see, we cant see their profile page, while their post and other things are present. like this:

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

> [@hosna](#):
>
> where is this exactly?

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.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 5, 2019, 9:41pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/13 "2019-11-05T21:41:27Z")

</div>

> [@tshenry](#):
>
> It’s worth a shot, but based on what you just posted, it sounds like there might be a deeper issue.

Unfortunately you are right. It didnt fix my problem.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 5, 2019, 10:13pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/14 "2019-11-05T22:13:19Z")

</div>

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

 ![Untitled](https://global.discourse-cdn.com/meta/original/3X/b/5/b53780fac705010eb166dde8430346caba275f44.png)

I think this might be related to the problem.

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [November 5, 2019, 10:48pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/15 "2019-11-05T22:48:08Z")

</div>

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](https://global.discourse-cdn.com/meta/original/3X/0/2/022eb72a14cea9514b089d0c2ba6f78ce496c86d.png)

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.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 5, 2019, 10:54pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/16 "2019-11-05T22:54:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 6, 2019, 8:33pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/17 "2019-11-06T20:33:16Z")

</div>

@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 .

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [November 6, 2019, 9:09pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/19 "2019-11-06T21:09:15Z")

</div>

Hey there 👋 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.

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 6, 2019, 9:14pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/20 "2019-11-06T21:14:44Z")

</div>

> [@tshenry](#):
>
> 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.

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

---

<div class="post-metadata">

### Author: ![hosna](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hosna/32/99969_2.png) [@hosna](https://meta.discourse.org/u/hosna)
#### Post date: [November 7, 2019, 7:52pm UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/21 "2019-11-07T19:52:25Z")

</div>

> [@tshenry](#):
>
> Hey there 👋 That is great to hear. I was hoping that a background job might come to rescue after some time passed.

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

---

<div class="post-metadata">

### Author: ![blattersturm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blattersturm/32/76134_2.png) [@blattersturm](https://meta.discourse.org/u/blattersturm)
#### Post date: [March 15, 2020, 10:21am UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/22 "2020-03-15T10:21:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 11, 2024, 8:15am UTC](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659/25 "2024-03-11T08:15:35Z")

</div>



[Next page](https://meta.discourse.org/t/critical-error-changed-username-user-got-broken/132659.md?page=2)
