User flair remains after user is removed from group

Most jobs are shown in For example if you changed a badge query, you could wait a day for the BadgeGrant job to run, or you could hurry it along by hitting the Trigger button manually. I don’t know which of those jobs updates the flairs though.

1 Like

Yes, except for a tiny edge case of an anonymous user which will see the old flair on some pages for 1 minute.

We will investigate and fix.


User flair also remains when primary group is changed to a new primary group that has a flair associated with it.

1 Like

This is now fixed here

Did you change the primary group using the bulk action “Make All Primary” on the single group page?


No, I changed the primary group of a single user on the user’s admin page.

1 Like

I’d like to let you know that the problem still persists in 2.8.0.beta4 (Commits · discourse/discourse · GitHub)

We haven’t updated yet to the latest commit as there are no changes present to fix this bug.
In our case, user flairs remain unchanged when we update groups via Discourse Connect SSO. We see the user is no present in the group, but flair remains.

Hope it helps identifying and fixing the bug.

This fix won’t work retroactively. You have to update the flairs for old users manually. May I know how many users are affected by this for you?

Wow. Well I don’t know the estimates. Based on our data flows, there may be dozens & hundreds of users leaving/joining specific groups via SSO each day.
Anyway I can count users with outdated (unlinked to groups) flairs?

And how does one even edit other users flairs? I couldn’t find such option in admin panel. Not saying that I’m gonna update so many users one by one to remove this bug’s legacy.

By the way, removing flair from group settings and uploading another flair image doesn’t help. Users out of this group still keep the group flair :frowning:

Just checking if someone knows what to do with this problem

Sorry to bump this post so many times, but this bug is really messing up with our community :frowning:
@vinothkannans do you have any suggestions on how to proceed with it’s effects for us?

User.where(flair_group_id: REPLACE_WITH_GROUP_ID).where.not(primary_group_id: REPLACE_WITH_GROUP_ID).update_all(flair_group_id: nil)

The above command can fix your issue. Run this in your rails console. Please take a backup before performing it.

Thank you for replying.
Do I understand correctly, that due to the effects of this bug, we should perform queries like these on daily or other frequency basis? The thing is that our users group are being updated daily + every time the user’s subscription status changes on the main website. Everything done via SSO.

No, you don’t need to run this regularly. Now the issue is fixed in the above commit. This command will fix the flairs for the users affected before.

I will check for an alternative solution tomorrow.

1 Like

Thanks, I will patiently wait for your investigation results before turning to rails queries.
Please let me know if I may be any help to you on this issue

@kinetiksoft below rails code should fix the issue for all the members in every group. It will remove the group flair from users if they don’t belong to that flair group anymore.

Note, you don’t need to run this script regularly. It is a one-time fix for those old affected users. Take a backup as a precaution before running it.

User.joins("LEFT OUTER JOIN group_users ON group_users.user_id = AND group_users.group_id = users.flair_group_id").where(group_users: { id: nil }).where.not(flair_group_id: nil).update_all(flair_group_id: nil)

Hey @vinothkannans,

Thank you! I will let you know once we run the query & will give some updates within upcoming days to see if there is no inconsistency with flairs to groups relations after that

1 Like

Also, I pushed another fix in the above commit. Make sure to upgrade your site after it’s merged.

1 Like

Great, sure, will take a look into upcoming commits in upgrade section.
Should we wait with SQL query from above or we can proceed with it without waiting for commit to be merged in our discourse instance?

You can run the command after the upgrade.


Dear @vinothkannans, we’re upgraded discourse version & ran the query you provided:

[1] pry(main)> User.joins("LEFT OUTER JOIN group_users ON group_users.user_id = AND group_users.group_id = users.flair_group_id").where(group_users: { id: nil }).where.not(flair_group_id: nil).update_all(flair_group_id: nil)
=> 370
[2] pry(main)> 

I see user flairs changed according to their group status. Thank you again for prompt assistance!