# Suspension emails fail with 'undefined method 'topic', other emails work fine

**URL:** https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403
**Category:** Bug
**Tags:** email
**Created:** [April 3, 2023, 4:14pm UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403 "2023-04-03T16:14:40Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 3, 2023, 4:14pm UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/1 "2023-04-03T16:14:40Z")

</div>

3.1.0.beta3

When a user is suspended, the email to them is not sent, and the error below is logged. All other email is delivered normally.

`Job exception: undefined method 'topic' for nil:NilClass`

**Backtrace**

```plaintext
/var/www/discourse/app/jobs/regular/user_email.rb:116:in `message_for_email' 
/var/www/discourse/app/jobs/regular/user_email.rb:76:in `send_user_email' 
/var/www/discourse/app/jobs/regular/user_email.rb:39:in `execute' 
/var/www/discourse/plugins/chat/lib/chat/user_email_extension.rb:6:in `execute' 
/var/www/discourse/app/jobs/regular/critical_user_email.rb:12:in `execute' 
/var/www/discourse/app/jobs/base.rb:249:in `block (2 levels) in perform' 
rails_multisite-4.0.1/lib/rails_multisite/connection_management.rb:80:in `with_connection'
/var/www/discourse/app/jobs/base.rb:236:in `block in perform' 
/var/www/discourse/app/jobs/base.rb:232:in `each' 
/var/www/discourse/app/jobs/base.rb:232:in `perform' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:202:in `execute_job' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:170:in `block (2 levels) in process' 
sidekiq-6.5.8/lib/sidekiq/middleware/chain.rb:177:in `block in invoke' 
/var/www/discourse/lib/sidekiq/pausable.rb:134:in `call' 
sidekiq-6.5.8/lib/sidekiq/middleware/chain.rb:179:in `block in invoke' 
sidekiq-6.5.8/lib/sidekiq/middleware/chain.rb:182:in `invoke' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:169:in `block in process' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:136:in `block (6 levels) in dispatch' 
sidekiq-6.5.8/lib/sidekiq/job_retry.rb:113:in `local' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:135:in `block (5 levels) in dispatch' 
sidekiq-6.5.8/lib/sidekiq.rb:44:in `block in <module:Sidekiq>' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:131:in `block (4 levels) in dispatch' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:263:in `stats' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:126:in `block (3 levels) in dispatch' 
sidekiq-6.5.8/lib/sidekiq/job_logger.rb:13:in `call' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:125:in `block (2 levels) in dispatch' 
sidekiq-6.5.8/lib/sidekiq/job_retry.rb:80:in `global' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:124:in `block in dispatch' 
sidekiq-6.5.8/lib/sidekiq/job_logger.rb:39:in `prepare' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:123:in `dispatch' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:168:in `process' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:78:in `process_one' 
sidekiq-6.5.8/lib/sidekiq/processor.rb:68:in `run' 
sidekiq-6.5.8/lib/sidekiq/component.rb:8:in `watchdog' 
sidekiq-6.5.8/lib/sidekiq/component.rb:17:in `block in safe_thread'

```

**Env**

```plaintext
hostname gaoa-discourse-app
process_id 11140
application_version ea4f7fb660cb4cb5cba3763e9a28352123d39591
current_db default
current_hostname forum.[xxx].com
job Jobs::CriticalUserEmail
problem_db default
time 8:54 am
opts type account_suspended
--- --- --- ---
--- ---
user_id 3919
user_history_id 41800
current_site_id default

```

Edit to add sidekiq status:

 ![sidekiq failed job](https://global.discourse-cdn.com/meta/original/4X/1/b/c/1bce1fa71f8358da5ead2a0df37a6c5dbf0a51ff.png)

---

<div class="post-metadata">

### Author: ![southpaw](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/southpaw/32/79352_2.png) [@southpaw](https://meta.discourse.org/u/southpaw)
#### Post date: [April 5, 2023, 2:57pm UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/2 "2023-04-05T14:57:19Z")

</div>

Hi @omarfilip,

I don’t have a solution for you, but I wanted to confirm I was able to replicate this experience on an installation of Discourse that does not have many plugins.

**Steps taken to replicate:**

1. Select a user from /admin/users/list/active and manually suspend with the suspend button.

![image](https://global.discourse-cdn.com/meta/original/4X/e/b/d/ebdd0b13bfddaddf3fd9ecf39081ade460de7a65.png)

1. Add text in the “Email message” field.

 ![image](https://global.discourse-cdn.com/meta/original/4X/3/4/e/34e14de3c4e3abe19e5d517ad693292c09d64353.png)

1. Click the suspend button and confirm the user is now suspended.

![image](https://global.discourse-cdn.com/meta/original/4X/9/3/9/93958e5e743a5089762cfa59960a98f19663c387.png)

**Result** : No email is sent, and there is a Job Exception in the error logs.

```plaintext
Message (3 copies reported)

Job exception: undefined method `topic' for nil:NilClass

Backtrace

/var/www/discourse/app/jobs/regular/user_email.rb:116:in `message_for_email'
/var/www/discourse/app/jobs/regular/user_email.rb:76:in `send_user_email'
/var/www/discourse/app/jobs/regular/user_email.rb:39:in `execute'
/var/www/discourse/plugins/chat/lib/chat/user_email_extension.rb:6:in `execute'
/var/www/discourse/app/jobs/regular/critical_user_email.rb:12:in `execute'
/var/www/discourse/app/jobs/base.rb:249:in `block (2 levels) in perform'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rails_multisite-4.0.1/lib/rails_multisite/connection_management.rb:80:in `with_connection'
/var/www/discourse/app/jobs/base.rb:236:in `block in perform'
/var/www/discourse/app/jobs/base.rb:232:in `each'
/var/www/discourse/app/jobs/base.rb:232:in `perform'

```

---

<div class="post-metadata">

### Author: ![southpaw](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/southpaw/32/79352_2.png) [@southpaw](https://meta.discourse.org/u/southpaw)
#### Post date: [April 10, 2023, 3:51pm UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/6 "2023-04-10T15:51:27Z")

</div>

Hi @omarfilip,

Did any of your suspension emails ever send?

The emails related to my test suspensions were sent 2023-04-09T10:10:00Z, with no further action from me, but new suspensions are still failing with the same error.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [April 10, 2023, 3:58pm UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/7 "2023-04-10T15:58:01Z")

</div>

Thanks for the report and the repro @omarfilip and @southpaw 👍

Someone has been assigned to look into it and should hopefully have some answers soon. 🤞 🙂

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 10, 2023, 4:05pm UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/8 "2023-04-10T16:05:19Z")

</div>

Same issue with new suspensions - they just pile into the failed queue.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 11, 2023, 1:06am UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/10 "2023-04-11T01:06:29Z")

</div>

Note, this is assigned out internally, we hope to work on a fix in the upcoming few days.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [April 15, 2023, 11:23am UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/12 "2023-04-15T11:23:53Z")

</div>

This should be fixed by: 👍

[https://github.com/discourse/discourse/pull/21054](https://github.com/discourse/discourse/pull/21054)

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 16, 2023, 3:14am UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/13 "2023-04-16T03:14:16Z")

</div>

Thanks. That cleared the stuck jobs in sidekiq right away. 👍

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [April 17, 2023, 8:38am UTC](https://meta.discourse.org/t/suspension-emails-fail-with-undefined-method-topic-other-emails-work-fine/260403/14 "2023-04-17T08:38:52Z")

</div>


