Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't deliver email until CustomMailer.templates is called #79

Open
graudeejs opened this issue Aug 29, 2019 · 2 comments
Open

Can't deliver email until CustomMailer.templates is called #79

graudeejs opened this issue Aug 29, 2019 · 2 comments
Assignees

Comments

@graudeejs
Copy link

graudeejs commented Aug 29, 2019

Hello!

I'm trying to add hanami-mailer to my project, however I seem to have found a bug.
When I try to deliver email I get an exception
App::Mail::Mailers::Foo::Bar.deliver

NoMethodError: undefined method `fetch' for nil:NilClass
from /home/graudeejs/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/hanami-mailer-1.3.1/lib/hanami/mailer/dsl.rb:85:in `templates'

However if I call .templates before .deliver it works

App::Mail::Mailers::Foo::Bar.templates
App::Mail::Mailers::Foo::Bar.deliver

I've created a small repo where this issue can be replicated:
https://github.com/graudeejs/hanami-mailer-issue-79

$ ./bin/console
[1] pry(main)> App::Mail::Mailers::Foo::Bar.deliver
NoMethodError: undefined method `fetch' for nil:NilClass
from /home/graudeejs/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/hanami-mailer-1.3.1/lib/hanami/mailer/dsl.rb:85:in `templates'
[2] pry(main)> 
@mereghost mereghost self-assigned this Sep 13, 2019
@mereghost
Copy link
Member

Hi @graudeejs, thanks for your bug report and the time spent to create a sample project.

What I could find there are 2 issues in there:

  1. The mailers need to be loaded before the call to Hanami::Mailer.load!.
  2. Zeitwerk (maybe)

hanami-mailer 1.x series keeps references to the included classes by subverting the included hook. So when load! is called a call to templates with no args is sent. The thing is this call is triggered on all classes that Hanami::Mailer was included (which in your example would be none as they would be loaded after).

I'm not sure that you can make Zeitwerk actually load the classes beforehand.

That being said, this all is changing on hanami-mailer 2.0, that you can check on the unstable branch

@graudeejs
Copy link
Author

  1. explains it.

I've since created my own simple mail abstraction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants