# Falhas em massa no envio de e-mails de trabalho: falta de usuário?

**URL:** https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590
**Category:** Support
**Created:** [15 Janeiro , 2019 14:07 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590 "2019-01-15T14:07:06Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [15 Janeiro , 2019 14:07 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/1 "2019-01-15T14:07:06Z")

</div>

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:

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

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [15 Janeiro , 2019 14:12 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/2 "2019-01-15T14:12:16Z")

</div>

How did you ‘clean it out’? Using the rails console?

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [15 Janeiro , 2019 14:48 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/3 "2019-01-15T14:48:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 14:23 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/4 "2019-01-16T14:23:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 Janeiro , 2019 14:26 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/5 "2019-01-16T14:26:29Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 14:28 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/6 "2019-01-16T14:28:45Z")

</div>

I don’t have a backup from before doing so unfortunately.

How do I create a new user and delete it (properly)?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 Janeiro , 2019 14:31 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/7 "2019-01-16T14:31:54Z")

</div>

## Take a backup first, this could cause issues

I’ve never done this, but try running:

```ruby
User.create!(id: 2, password: SecureRandom.hex, email: "temp@example.com", username: 'someusername')

```

Then that user **should** appear in the user interface, and you can try deleting it from the admin panel.

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 15:07 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/8 "2019-01-16T15:07:38Z")

</div>

> [@david](#):
>
> User.create!(id: 2, password: SecureRandom.hex, email: “[temp@example.com](mailto:temp@example.com)”, username: ‘someusername’)

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?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 Janeiro , 2019 15:09 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/9 "2019-01-16T15:09:25Z")

</div>

Does it appear at `/admin/users/39129/username`?

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 15:10 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/10 "2019-01-16T15:10:11Z")

</div>

That gives me a 404 😕

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 Janeiro , 2019 15:11 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/11 "2019-01-16T15:11:28Z")

</div>

Oops, I meant to change the number there

```plaintext
/admin/users/2/username

```

Also sorry for editing your post, I hit the wrong button!

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 15:15 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/12 "2019-01-16T15:15:47Z")

</div>

> [@david](#):
>
> /admin/users/2/username

Ah, that does give me a page of the user!

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 15:16 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/13 "2019-01-16T15:16:09Z")

</div>

Shall I click Delete User on that page?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 Janeiro , 2019 15:16 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/14 "2019-01-16T15:16:50Z")

</div>

Give it a try. That should then run through the ‘proper’ deletion process

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 15:17 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/15 "2019-01-16T15:17:23Z")

</div>

> There was an error deleting that user. Make sure all posts are deleted before trying to delete the user

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 Janeiro , 2019 15:18 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/16 "2019-01-16T15:18:46Z")

</div>

Check `/logs` to see a more detailed error (hopefully)

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 15:23 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/17 "2019-01-16T15:23:23Z")

</div>

I don’t see anything beneath $SITE/logs, but in /shared/log/rails/production.log I can see the following:

````Started
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)```
````

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 Janeiro , 2019 15:24 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/18 "2019-01-16T15:24:38Z")

</div>

Try running

```plaintext
User.find(2).primary_email

```

on the console. I guess it will say `nil`?

---

<div class="post-metadata">

### Author: ![aknudsen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aknudsen/32/115845_2.png) [@aknudsen](https://meta.discourse.org/u/aknudsen)
#### Post date: [16 Janeiro , 2019 15:26 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/19 "2019-01-16T15:26:22Z")

</div>

```plaintext
[2] pry(main)> User.find(2).primary_email
=> nil

```

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [16 Janeiro , 2019 15:27 UTC](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590/20 "2019-01-16T15:27:35Z")

</div>

Ok, it looks like you deleted the UserEmail record rather than the user. So try

```plaintext
u = User.find(2)
u.email = "temp@example.com"
u.save!

```

Then try deleting from the UI again

[Próxima página](https://meta.discourse.org/t/getting-email-job-failures-en-masse-due-to-missing-user/106590.md?page=2)
