# Email-in topic\_creator bug

**URL:** https://meta.discourse.org/t/email-in-topic-creator-bug/102658
**Category:** Bug
**Created:** [November 24, 2018, 11:04am UTC](https://meta.discourse.org/t/email-in-topic-creator-bug/102658 "2018-11-24T11:04:17Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sizeof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sizeof/32/131954_2.png) [@sizeof](https://meta.discourse.org/u/sizeof)
#### Post date: [November 24, 2018, 11:04am UTC](https://meta.discourse.org/t/email-in-topic-creator-bug/102658/1 "2018-11-24T11:04:18Z")

</div>

Hello,

I set up pop polling using Gmail. Discourse fails to create new posts on some of the e-mails, not all.  
I checked the logs and found the following error message and backtrace:

> Unrecognized error type (NoMethodError: undefined method `\>’ for nil:NilClass) when processing incoming email

```plaintext
Backtrace:
> /var/www/discourse/lib/topic_creator.rb:161:in `setup_tags'
> /var/www/discourse/lib/topic_creator.rb:37:in `create'
> /var/www/discourse/lib/post_creator.rb:406:in `create_topic'
> /var/www/discourse/lib/post_creator.rb:167:in `block in create'
> /var/www/discourse/lib/post_creator.rb:331:in `block in transaction'
> /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `block in transaction'
> /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:230:in `block in within_new_transaction'
> /usr/local/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
> /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:227:in `within_new_transaction'
> /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `transaction'
> /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/transactions.rb:212:in `transaction'
> /var/www/discourse/lib/post_creator.rb:330:in `transaction'
> /var/www/discourse/lib/post_creator.rb:165:in `create'
> /var/www/discourse/lib/new_post_manager.rb:204:in `perform_create_post'
> /var/www/discourse/lib/new_post_manager.rb:178:in `perform'
> /var/www/discourse/lib/email/receiver.rb:988:in `create_post'
> /var/www/discourse/lib/email/receiver.rb:895:in `create_post_with_attachments'
> /var/www/discourse/lib/email/receiver.rb:850:in `create_topic'
> /var/www/discourse/lib/email/receiver.rb:596:in `process_destination'
> /var/www/discourse/lib/email/receiver.rb:166:in `block in process_internal'
> /var/www/discourse/lib/email/receiver.rb:164:in `yield'
> /var/www/discourse/lib/email/receiver.rb:164:in `each'
> /var/www/discourse/lib/email/receiver.rb:164:in `each'
> /var/www/discourse/lib/email/receiver.rb:164:in `each'
> /var/www/discourse/lib/email/receiver.rb:164:in `each'
> /var/www/discourse/lib/email/receiver.rb:164:in `process_internal'
> /var/www/discourse/lib/email/receiver.rb:74:in `block in process!'
> /var/www/discourse/lib/distributed_mutex.rb:34:in `synchronize'
> /var/www/discourse/lib/distributed_mutex.rb:5:in `synchronize'
> /var/www/discourse/lib/email/receiver.rb:68:in `process!'
> /var/www/discourse/lib/email/processor.rb:18:in `process!'
> /var/www/discourse/lib/email/processor.rb:12:in `process!'
> /var/www/discourse/app/jobs/scheduled/poll_mailbox.rb:25:in `process_popmail'
> /var/www/discourse/app/jobs/scheduled/poll_mailbox.rb:43:in `block (2 levels) in poll_pop3'
> /usr/local/lib/ruby/2.5.0/net/pop.rb:666:in `each'
> /usr/local/lib/ruby/2.5.0/net/pop.rb:666:in `each_mail'
> /var/www/discourse/app/jobs/scheduled/poll_mailbox.rb:42:in `block in poll_pop3'
> /usr/local/lib/ruby/2.5.0/net/pop.rb:532:in `start'
> /var/www/discourse/app/jobs/scheduled/poll_mailbox.rb:41:in `poll_pop3'
> /var/www/discourse/app/jobs/scheduled/poll_mailbox.rb:16:in `execute'
> /var/www/discourse/app/jobs/base.rb:137:in `block (2 levels) in perform'
> /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/rails_multisite-2.0.4/lib/rails_multisite/connection_management.rb:63:in `with_connection'
> /var/www/discourse/app/jobs/base.rb:127:in `block in perform'
> /var/www/discourse/app/jobs/base.rb:123:in `each'
> /var/www/discourse/app/jobs/base.rb:123:in `perform'
> /var/www/discourse/app/jobs/base.rb:185:in `perform'
> /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mini_scheduler-0.8.1/lib/mini_scheduler/manager.rb:81:in `process_queue'
> /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mini_scheduler-0.8.1/lib/mini_scheduler/manager.rb:29:in `block in initialize'

```

I tried changing [/var/www/discourse/lib/topic\_creator.rb line 161](https://github.com/discourse/discourse/blob/master/lib/topic_creator.rb#L161) to

> if category && !category.nil? && category.present? && category.minimum\_required\_tags \> 0

and restarted unicorn. But the problem persists. It still displays the same message.

---

<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: [November 24, 2018, 11:10am UTC](https://meta.discourse.org/t/email-in-topic-creator-bug/102658/2 "2018-11-24T11:10:21Z")

</div>

It sounds like you’re seeing the same issue as here. Can you try following this workaround on the category you are trying to post in:

> [@Internal server error setting tags via the api](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/8):
>
> Hi @Akki9326, it looks like we have a bug here. To work around it for now, open up the preferences for the category, and set the “Minimum number of tags required in a topic” setting to zero. We will look at getting this fixed so it can’t happen in the future.

I will look at fixing this properly next week, as it should not be possible for it to break like this.

---

<div class="post-metadata">

### Author: ![sizeof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sizeof/32/131954_2.png) [@sizeof](https://meta.discourse.org/u/sizeof)
#### Post date: [November 24, 2018, 11:16am UTC](https://meta.discourse.org/t/email-in-topic-creator-bug/102658/4 "2018-11-24T11:16:22Z")

</div>

Yep, for now, that did the trick. Apologies for posting the same issue again, and thanks for the solution!

Best regards,  
sizeof

---

<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: [November 24, 2018, 11:17am UTC](https://meta.discourse.org/t/email-in-topic-creator-bug/102658/5 "2018-11-24T11:17:11Z")

</div>

> [@sizeof](#):
>
> Apologies for posting the same issue agai

No worries, now we know that it wasn’t a one-off, so will be double-sure to get it fixed! 🙂

---

<div class="post-metadata">

### Author: ![sizeof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sizeof/32/131954_2.png) [@sizeof](https://meta.discourse.org/u/sizeof)
#### Post date: [November 24, 2018, 11:29am UTC](https://meta.discourse.org/t/email-in-topic-creator-bug/102658/6 "2018-11-24T11:29:59Z")

</div>

Just an FYI.

When I opened the Settings tab the Minimum required tags field had no number. Then it clicked. I should’ve checked if category.minimum\_required\_tags is nil, not category. So changing it to

> if category.present? && category.minimum\_required\_tags && !category.minimum\_required\_tags.nil? && category.minimum\_required\_tags \> 0

seems to fix the issue. But this feels like a hack. I’m not sure why the field is missing a value and according to that the issue might be elsewhere. That field should have an integer value only. And I guess the extra check if it’s nil is not a bad thing since you can never trust user input 🙂

---

<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: [November 29, 2018, 5:11pm UTC](https://meta.discourse.org/t/email-in-topic-creator-bug/102658/7 "2018-11-29T17:11:50Z")

</div>

Fixed by @maja 🎊

[https://github.com/discourse/discourse/commit/4a8f21d38743a0a6b2a161889e335581248583b9](https://github.com/discourse/discourse/commit/4a8f21d38743a0a6b2a161889e335581248583b9)

---

<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: [November 29, 2018, 5:11pm UTC](https://meta.discourse.org/t/email-in-topic-creator-bug/102658/8 "2018-11-29T17:11:52Z")

</div>


