Missing template when sending emails

In our multisite installation, Discourse regularly fails sending email because it is missing templates:

Job exception: Missing template layouts/email_template with {:locale=>[:en_US, :en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :vtt, :png, :jpeg, :gif, :bmp, :tiff, :svg, :mpeg, :mp3, :ogg, :m4a, :webm, :mp4, :otf, :ttf, :woff, :woff2, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :gzip], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}. Searched in:
  * "/var/www/discourse/public/app/views"

Here’s the backtrace:

/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/path_set.rb:48:in `find'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/lookup_context.rb:129:in `find'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/renderer/template_renderer.rb:47:in `determine_template'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/renderer/template_renderer.rb:9:in `render'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/renderer/renderer.rb:61:in `render_template_to_object'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/renderer/renderer.rb:29:in `render_to_object'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/renderer/renderer.rb:22:in `render'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/helpers/rendering_helper.rb:34:in `block in render'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/base.rb:304:in `in_rendering_context'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.0/lib/action_view/helpers/rendering_helper.rb:30:in `render'
/var/www/discourse/lib/email/renderer.rb:25:in `html'
/var/www/discourse/lib/email/sender.rb:67:in `block in send'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mail-2.7.1/lib/mail/message.rb:153:in `instance_eval'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mail-2.7.1/lib/mail/message.rb:153:in `initialize'
/var/www/discourse/lib/email/sender.rb:65:in `new'
/var/www/discourse/lib/email/sender.rb:65:in `send'
/var/www/discourse/app/jobs/regular/user_email.rb:63:in `execute'
/var/www/discourse/app/jobs/regular/critical_user_email.rb:16:in `execute'
/var/www/discourse/app/jobs/base.rb:232:in `block (2 levels) in perform'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.0.7/lib/rails_multisite/connection_management.rb:220:in `with_connection'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rails_multisite-2.0.7/lib/rails_multisite/connection_management.rb:60:in `with_connection'
/var/www/discourse/app/jobs/base.rb:221:in `block in perform'
/var/www/discourse/app/jobs/base.rb:217:in `each'
/var/www/discourse/app/jobs/base.rb:217:in `perform'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:192:in `execute_job'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:165:in `block (2 levels) in process'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/middleware/chain.rb:128:in `block in invoke'
/var/www/discourse/lib/sidekiq/pausable.rb:138:in `call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/middleware/chain.rb:133:in `invoke'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:164:in `block in process'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:137:in `block (6 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/job_retry.rb:109:in `local'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:136:in `block (5 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq.rb:37:in `block in <module:Sidekiq>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:132:in `block (4 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:250:in `stats'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:127:in `block (3 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/job_logger.rb:8:in `call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:126:in `block (2 levels) in dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/job_retry.rb:74:in `global'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:125:in `block in dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/logging.rb:48:in `with_context'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/logging.rb:42:in `with_job_hash_context'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:124:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:163:in `process'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:83:in `process_one'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:71:in `run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/util.rb:16:in `watchdog'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/sidekiq-5.2.7/lib/sidekiq/util.rb:25:in `block in safe_thread'

The problem is solved by rebuilding, but it re-occurs regularly – probably when using the web updater, but I haven’t managed to validate that theory yet.
Once the issue has manifested, Discourse is completely unable to send any emails until I rebuild.

What’s going on here?

2 Likes

We’re not seeing this error on any of our hosted sites. Do you have any unofficial plugins installed?

This should be /var/www/discourse/app/views… One possible explanation is that a plugin has run cd public, and not returned to the app directory afterwards.

A simple restart will probably have the same effect - either ./launcher restart app, or enter the container and run sv restart unicorn.

3 Likes

We do have unofficial plugins, but I don’t think they are responsible:

- git clone https://github.com/discourse/docker_manager.git
- git clone https://github.com/discourse/discourse-spoiler-alert.git
- git clone https://github.com/discourse/discourse-data-explorer.git
- git clone https://github.com/discourse/discourse-staff-notes.git
- git clone https://github.com/cpradio/discourse-plugin-checklist.git
- git clone https://github.com/fefrei/discourse-pseuco-onebox.git
- git clone https://github.com/discourse/discourse-math.git
- git clone https://github.com/discourse/discourse-oauth2-basic.git
- git clone https://github.com/discourse/discourse-chat-integration.git

discourse-plugin-checklist is very common, and discourse-pseuco-onebox is a very simple plugin that just defines a Onebox, nothing else.

I’ll try that the next time this issue resurfaces.

2 Likes