A user, hannes_e, is experiencing an issue when trying to grant admin rights to a user, resulting in an error message “Validation failed: Name has already been taken”. The error occurs after clicking the confirmation link in the email and then the “Grant Admin Access” button. pfaffman asks for clarification on the steps taken, and hannes_e provides more details on the process.
sam suggests checking the group names and IDs in the database, as Discourse is particular about these IDs. hannes_e provides the output of the command, which shows that the staff group is missing and instead has a group named Staff with a different ID. sam recommends renaming the Staff group to staff. However, the UI does not allow this, and hannes_e is unsure how to proceed.
sam advises hannes_e to try renaming the group directly in the database, which ultimately resolves the issue. hannes_e suggests that renaming system groups should be disallowed in the UI to prevent similar issues. sam agrees that it should not be possible to get into this state. The solution involves updating the group name in the database using the command update groups set name='staff' where id=3;.
I checked the logs and found the following messages:
ActiveRecord::RecordInvalid (Validation failed: Name has already been taken) app/models/group.rb:607:in 'refresh_automatic_group!' app/models/group.rb:666:in 'block in refresh_automatic_groups!' app/m
Failed to handle exception in exception app middleware : ActiveRecord::RecordInvalid : Validation failed: Name has already been taken
At about the same time I also get a message about MaxMind not working properly, not sure whether this has anything to do with it (didn’t find any related settings in the admin interface):
MaxMindDB (/var/www/discourse/vendor/data/GeoLite2-City.mmdb) could not be found: No such file or directory @ rb_sysopen - /var/www/discourse/vendor/data/GeoLite2-City.mmdb
I click the “Grant Admin” button, application presents me with a modal “We’ve sent you an email to verify the new administrator. Please open it and follow the instructions.”
I click the confirmation link in the email (“Confirm Administrator Account”) which brings me to a confirmation page.
On the confirmation page I click the button “Grant Admin Access”, which then produces the error page (see screenshot in my original post) and also the error messages in the log.
I also just noticed the following message further up in the log (prefixed with the number 46 - does this mean that it has been repeated 46 times?):
Error ensuring consistency for Group: Validation failed: Name has already been taken
Discourse is very particular about these ids, staff must be 2, admins must be 1. If somehow you have a different group with that name there could be trouble. I would also ensure no user is called admins
It looks like this (there are many more groups, but they were clearly created by us and didn’t have any resemblance with the system groups, so I didn’t include them below):
I notice that there is no group staff, only Staff - if staff always has id 3 then I guess this indicates that somebody removed it and created a new group (id 42).
Is it enough to create staff again or how can I solve this?
Yes, this did the trick! The group existed, but somebody had renamed it - since this basically breaks core functionality I am wondering whether renaming of system groups should be disallowed in the UI.
For the records, in case somebody ends up in a similar situation:
docker exec -it app /bin/bash
su - postgres
psql -d discourse
discourse=# update groups set name='staff' where id=3;
\q