Strange issue on with 3.0, background jobs, Heroku and HTML email attachments
samstickland opened this issue · 7 comments
Hi,
After mime-types upgraded to 3.0 and brought mime-types-data 3.2016.0221 along with it I started getting errors from my Heroku background jobs (via delayed-job) when they try to send an email.
undefined method `type_for' for MIME::Types:Class
This was fired when we try to attach an HTML attachment via:
attachments.inline['logo.png'] = logo
I could not reproduce this locally, either via deliver_now
or deliver_later
+ rake jobs:workoff
However locking mime-types to '<3' has 'fixed' the issue.
I'm not sure where to start investigating this, since I am having trouble reproducing anywhere except production (which is not the ideal test environment ;)
The same error message has been reported by someone else here: http://stackoverflow.com/questions/36709845/cannot-add-inline-attachment-with-actionmailer-in-rails-3 Although the circumstances are possibly a little different.
I need more information than I have. At a minimum, I need a bigger backtrace, but that won’t probably be enough. Ideally, you can create a sample project that does this on a Heroku hobby project where we can add some deeper logging to figure out what’s going on. I remember seeing something that suggests Heroku hobby projects can have one hobby worker, and you can configure the mailer bits to send to a mail trap so that you’re not even sending accidental spam through this worker.
Sure. It will take me little time to create a sample project, but in the meantime, here is a bigger portion of the backtrace:
1
File "/app/vendor/bundle/ruby/2.3.0/gems/attr_encrypted-1.3.5/lib/attr_encrypted.rb" line 259 in method_missing
2
File "/app/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/attachments_list.rb" line 102 in set_mime_type
3
File "/app/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/attachments_list.rb" line 42 in []=
4
File "/app/app/mailers/timesheets_mailer.rb" line 16 in notify_approver_of_submission
- 123 non-project frames
5
File "/app/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.5/lib/abstract_controller/base.rb" line 198 in process_action
6
File "/app/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.5/lib/abstract_controller/callbacks.rb" line 20 in block in process_action
7
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 88 in __run_callbacks__
8
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 778 in _run_process_action_callbacks
9
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 81 in run_callbacks
10
File "/app/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.5/lib/abstract_controller/callbacks.rb" line 19 in process_action
11
File "/app/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.5/lib/abstract_controller/base.rb" line 137 in process
12
File "/app/vendor/bundle/ruby/2.3.0/gems/actionview-4.2.5/lib/action_view/rendering.rb" line 30 in process
13
File "/app/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/base.rb" line 596 in block in process
14
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb" line 164 in block in instrument
15
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb" line 20 in instrument
16
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb" line 164 in instrument
17
File "/app/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/base.rb" line 593 in process
18
File "/app/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/base.rb" line 584 in initialize
19
File "/app/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/message_delivery.rb" line 25 in new
20
File "/app/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/message_delivery.rb" line 25 in __getobj__
21
File "/app/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/message_delivery.rb" line 34 in message
22
File "/app/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/message_delivery.rb" line 85 in deliver_now
23
File "/app/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.5/lib/action_mailer/delivery_job.rb" line 10 in perform
24
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/execution.rb" line 32 in block in perform_now
25
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 117 in call
26
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 555 in block (2 levels) in compile
27
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 505 in call
28
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 498 in block (2 levels) in around
29
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 343 in block (2 levels) in simple
30
File "/app/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.14.1.311/lib/new_relic/agent/instrumentation/active_job.rb" line 46 in perform
31
File "/app/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.14.1.311/lib/new_relic/agent/instrumentation/active_job.rb" line 20 in block (3 levels) in <top (required)>
32
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 441 in instance_exec
33
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 441 in block in make_lambda
34
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 342 in block in simple
35
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 497 in block in around
36
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 505 in call
37
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 498 in block (2 levels) in around
38
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 343 in block (2 levels) in simple
39
File "/app/vendor/bundle/ruby/2.3.0/gems/i18n-0.7.0/lib/i18n.rb" line 257 in with_locale
40
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/translation.rb" line 7 in block (2 levels) in <module:Translation>
41
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 441 in instance_exec
42
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 441 in block in make_lambda
43
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 342 in block in simple
44
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 497 in block in around
45
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 505 in call
46
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 498 in block (2 levels) in around
47
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 343 in block (2 levels) in simple
48
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/logging.rb" line 23 in block (4 levels) in <module:Logging>
49
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb" line 164 in block in instrument
50
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb" line 20 in instrument
51
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb" line 164 in instrument
52
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/logging.rb" line 22 in block (3 levels) in <module:Logging>
53
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/logging.rb" line 43 in block in tag_logger
54
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb" line 68 in block in tagged
55
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb" line 26 in tagged
56
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb" line 68 in tagged
57
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/logging.rb" line 43 in tag_logger
58
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/logging.rb" line 19 in block (2 levels) in <module:Logging>
59
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 441 in instance_exec
60
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 441 in block in make_lambda
61
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 342 in block in simple
62
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 497 in block in around
63
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 505 in call
64
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 92 in __run_callbacks__
65
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 778 in _run_perform_callbacks
66
File "/app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb" line 81 in run_callbacks
67
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/execution.rb" line 31 in perform_now
68
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/execution.rb" line 21 in execute
69
File "/app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.5/lib/active_job/queue_adapters/delayed_job_adapter.rb" line 34 in perform
Thanks. I have also commented on the SO thread indicating that downgrading isn’t the right answer and asking that poster for more information on this bug. I think that this is an Other bug (I say upstream in my comment, but I guess it’s actually downstream from mime-types…), because I didn’t change any of that code, but I can’t figure out why downgrading to 2.x would make a difference.
Hi. Are you able to share your Gemfile
, especially if you have a line for mime-types
? I think that I have a clue as to what is happening.
Hi, @samstickland. At your earliest convenience, can you try this again with mime-types 3.1? The only thing I can guess is that somehow mime-types was partially loading for your background jobs, but somehow not getting through lib/mime/types/registry.rb
, which is where I moved the class methods when I released mime-types 3. I had some code that called out as problematic (it was done to fix a circular require that happened because I made columnar loading the default.
I have changed how all this loads so that there’s no guard clauses for circular requires now, just smarter loading in general.
Hi,
I've just tried this with 3.1 and emails are now sent correctly from the background job!
Thanks for your help :)
Glad that this worked out. I have put a comment on the SO issue as well.