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

Issues using this gem outside of Rails #257

Open
wout opened this issue Apr 26, 2024 · 1 comment
Open

Issues using this gem outside of Rails #257

wout opened this issue Apr 26, 2024 · 1 comment
Assignees

Comments

@wout
Copy link

wout commented Apr 26, 2024

Using the example code from the docs to send an email, this gem raises the following error:

/home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/mailjet-1.7.10/lib/mailjet/resource.rb:345:in `block in formatted_payload': undefined method `blank?' for false (NoMethodError)

        v.blank?
         ^^^^^^^
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.2/lib/active_support/hash_with_indifferent_access.rb:334:in `reject!'
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.2/lib/active_support/hash_with_indifferent_access.rb:334:in `block in reject'
	from <internal:kernel>:90:in `tap'
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.2/lib/active_support/hash_with_indifferent_access.rb:334:in `reject'
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/mailjet-1.7.10/lib/mailjet/resource.rb:344:in `formatted_payload'
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/mailjet-1.7.10/lib/mailjet/resource.rb:281:in `save'
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/mailjet-1.7.10/lib/mailjet/resource.rb:304:in `save!'
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/mailjet-1.7.10/lib/mailjet/resource.rb:125:in `block in create'
	from <internal:kernel>:90:in `tap'
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/mailjet-1.7.10/lib/mailjet/resource.rb:124:in `create'
	from (irb):7:in `<main>'
	from <internal:kernel>:187:in `loop'
	from /home/wout/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/irb-1.11.0/exe/irb:9:in `<top (required)>'
	from /home/wout/.rbenv/versions/3.3.0/bin/irb:25:in `load'
	from /home/wout/.rbenv/versions/3.3.0/bin/irb:25:in `<main>'

That's because the persisted property (boolean) is also stored in the attributes object: https://github.com/mailjet/mailjet-gem/blob/master/lib/mailjet/resource.rb#L344

I could get around it by monkey-patching the code:

      payload = attributes.reject do |_, v|
        v.nil? ||
          (v.is_a?(String) && v.strip.empty?) ||
          (v.respond_to?(:empty?) && v.empty?)
      end

But I'm not sure if that covers all cases.

@mgrishko mgrishko self-assigned this Apr 29, 2024
@Juksefantomet
Copy link

Adding some more details here 😄

I had the same issue, this was in my case due to ruby v3.3.3.

I rolled my Ruby version down to 2.6.6 (which was being used in a working project) for testing purposes and the mailjet gem did not attempt this "stunt" and the email was sent successfully.

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

No branches or pull requests

3 participants