Email-in topic_creator bug

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

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 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.

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:

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

4 Likes

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

Best regards,
sizeof

1 Like

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

2 Likes

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 :slight_smile:

2 Likes

Fixed by @maja :confetti_ball:

6 Likes