This project is archived and is in readonly mode.
TMail Autoloading Issue
-
talksense101
- Tag set to 2.3
I get the same error. I installed 2.3 by following instructions on the Rails weblog at rubyonrails.org
-
Marcus Mateus
I think it may have something to do with the use of the new autoload functionality in action_mailer.rb, "autoload :TMail, 'action_mailer/vendor/tmail'"
I changed that line to "require 'action_mailer/vendor/tmail'" and things it appear to work now... hopefully another clue to root cause. Good enough for me to continue the upgrade to 2.3 for now anyway.
-
Marcus Mateus
- Tag changed from 2.3 to 2.3, autoload
- Title changed from TMail::Encoder NameError to TMail Autoloading Issue
Okay, I have spent far to much time working on this and have managed to root cause the error and write tests that replicate the issue, but I need help finding a good long-term solution.
Root Cause:
Steps to Reproduce
*tmail gem version '~> 1.2.3' is present *require 'tmail' is run prior to any call using the TMail constant
Failure Reason
When the require is called prior to any call using the TMail constant, the autoload is actually invoked from within the require. This occurs when the gem is loading and tries to define the TMail module. At that point, the gem is only half-loaded, yet the constant is undefined so rails attempts to "autoload" it. When the autoload code runs and attempts to set a constant on the as yet undefined TMail::Encoder an exception is thrown.
Work Around
The best work around is for those experiencing this issue to add the following somewhere towards the top of their environment.rb (ie. before Rails::Initializer.run):
Module TMail end
Doing this ensures that for most people using utf-8 the MAX_LINE_LEN constant is still properly set by the autoloader, and for the rest of us the gem works. In fact someone needing both the gem and utf-8 can simply set the constant themselves later.
Partial Patch w/ Failing Tests
I have written tests which reproduce the error with a tmail gem present, and check that the TMail::Encoder::MAX_LINE_LEN is properly set. Unfortunately, I have not been able to come up with a way to easily ensure that both tests pass. Currently the gem is able to load fully, but the constant is not properly set. Maybe there is some way to ensure it is loaded when UTF-8 is used instead??
If anyone, an autoload expert perhaps?, has any ideas I would really appreciate it... I'm officially stumped.
-
Marcus Mateus
Darn formatting is all messed up (preview would be nice), but hopefully you get the idea.
Marcus
-
Nicholas Faiz
Marcus,
Thanks for posting the workaround. It's something to use in the meantime, at least. Will test it on Tuesday.
-
Marcus Mateus
- Assigned user set to josh
After some more thought on this issue, I think the best mid-term solution is actually to simply require TMail, rather than autoloading it in action_mailer.rb... I can not think of another reliable way to avoid the re-entry condition described above.
Joshua, assigning to you since from the commit history it looks like you were involved in a lot of the original autoloading changes. Please reassign it to the appropriate person if it should be someone else.
If any of what I have described is not clear, please let me know and I will do my best to post a follow up.
Thanks, Marcus
-
josh
- Milestone cleared.
-
Repository
- State changed from new to resolved
(from [5c684f518feeaf38961f976b966e57abf386e248]) Just require tmail instead of autoloading it to fix issues when using the gem version [#1851 TMail Autoloading Issue state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
