Merging user failing

AI-generated summary

Merging User Failing

Alexander_Wright is experiencing an error when attempting to merge duplicate user accounts created due to an issue with their SSO provider. The error message indicates a NoMethodError related to an undefined email method for a nil object.

The error log points to app/models/user.rb:1243 and suggests the issue may be related to the target user not having a primary email address. gerhard proposes a solution in the form of a GitHub pull request (https://github.com/discourse/discourse/pull/11446), which may resolve the issue.

I’m getting an error when trying to merge two user accounts.

I had a problem with my SSO provider giving a different ID. This has caused a small number of users to end up with duplicate accounts.

The SSO issue is now fixed, and I’m trying to merge the duplicate accounts.

When going through the admin merge function, I get a message box saying an error has occurred, and the following in the logs. The accounts are not merged.

Error Log
Message (2 copies reported)

NoMethodError (undefined method `email' for nil:NilClass)
app/models/user.rb:1243:in `email'
app/services/user_merger.rb:8:in `initialize'
app/controllers/admin/users_controller.rb:507:in `new'
app/controllers/admin/users_controller.rb:507:in `merge'
app/controllers/application_controller.rb:358:in `block in with_resolved_locale'
app/controllers/application_controller.rb:358:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:68:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:354:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:22:in `call'
lib/middleware/request_tracker.rb:176:in `call'

Backtrace

app/models/user.rb:1243:in `email'
app/services/user_merger.rb:8:in `initialize'
app/controllers/admin/users_controller.rb:507:in `new'
app/controllers/admin/users_controller.rb:507:in `merge'
actionpack (6.0.3.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.3.3) lib/abstract_controller/base.rb:195:in `process_action'
actionpack (6.0.3.3) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.3.3) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.3.3) lib/active_support/callbacks.rb:112:in `block in run_callbacks'
app/controllers/application_controller.rb:358:in `block in with_resolved_locale'

Env

HTTP HOSTS: discourse.camra.org.uk

Looks like the user you are trying to merge doesn’t have a primary email address. This should fix it:

https://github.com/discourse/discourse/pull/11446

4 Likes