A user, aknudsen, is experiencing email job failures due to a missing user with ID 2, which they believe was accidentally created via SSO and subsequently deleted. Despite removing the user via the Rails console, remnants of the user remain, causing errors like undefined method 'email' for nil:NilClass. david advises against direct database manipulation and suggests recreating the user with ID 2 to properly delete it through the admin interface. aknudsen confirms the user still exists but isn’t visible in the UI. After further troubleshooting, david identifies that the UserEmail record was deleted instead of the user, and suggests updating the user’s email to allow proper deletion. aknudsen confirms this resolves the issue.
I’m getting a lot of email job failures, when I check the logs in Sidekiq, I can see that they’re related to a user with ID 2. The failures are on this form:
Jobs::HandledExceptionWrapper: Wrapped NoMethodError: undefined method `email' for nil:NilClass
I think the user with ID 2 was created by accident through logging on with SSO using the wrong email address, and I since cleaned it out. I guess that user ID is somehow still lingering in parts of the system? How can I verify that these issues are indeed relating to a non-existent user, and if so get rid of it?
Yeah I used the rails console to remove the user. I think I removed the main database record. I found there was an SSO record lingering after though, so I reset the SSO records too somehow.
Any idea how to troubleshoot what’s going wrong here? As I said, I don’t think there’s a user record with ID 2 any longer. Unless another user was added with that ID in the meantime, there seems to be remnants in the system causing these email errors.
Deleting a user is a complicated process, and by doing it on the console you have bypassed all the safeguards in place. If you can restore a backup and do it from the user interface, that would be best.
If not, maybe you could try creating a new user object on the console using the same ID as the old user, and then deleting that user properly. I would strongly recommend taking a backup before attempting that, as I’m not sure exactly what will happen.
Thanks! I tried creating the user now, as you said, but it turns out the record with ID 2 is still there, even though I thought I had deleted it! It doesn’t show up among the users in the Discourse UI though. Is there anything I can do further to resolve this issue?
I don’t see anything beneath $SITE/logs, but in /shared/log/rails/production.log I can see the following:
Processing by Admin::UsersController#destroy as JSON
Parameters: {"context"=>"/admin/users/2/username", "delete_posts"=>"true", "id"=>"2"}
Rendering text template
Rendered text template (0.0ms)
Completed 418 in 11ms (Views: 3.2ms | ActiveRecord: 3.4ms)
Failed to process hijacked response correctly : undefined method `email' for nil:NilClass
Started GET "/admin/users/2.json?_=1547652146066" for 185.199.104.14 at 2019-01-16 15:22:31 +0000
Processing by Admin::UsersController#show as JSON
Parameters: {"_"=>"1547652146066", "id"=>"2"}
Completed 200 OK in 64ms (Views: 0.2ms | ActiveRecord: 42.7ms)```