Skip to content

Fix wrong arity in AM defaults procs - #4627

Closed
jbourassa wants to merge 1 commit into
heartcombo:masterfrom
jbourassa:fix-am-defaults-arity
Closed

jbourassa wants to merge 1 commit into
heartcombo:masterfrom
jbourassa:fix-am-defaults-arity

Conversation

@jbourassa

Copy link
Copy Markdown

Support Rails 5.1 + 5.0 by using the right arity for the proc.
Rails 5.1 changed the arity from 0 to 1.

See rails/rails#30391 and #4604 for details.

Support Rails 5.1 + 5.0 by using the right arity for the proc.
Rails 5.1 changed the arity from 0 to 1.

See rails/rails#30391 and #4604 for details.
@tegon

tegon commented Jan 23, 2018

Copy link
Copy Markdown
Member

Hello @jbourassa, thanks for your report.
I've just tested here with a new Rails 5.1.4 application and I haven't got this error during password reset.
Can you provide us a sample application that reproduces the issue in isolation?
That would help us find the issue.

Thank you!

@jbourassa

Copy link
Copy Markdown
Author

Hey @tegon,

Here's a project where you can reproduce the issue: https://github.com/jbourassa/devise-4627-repro

It's a stock Rails 5.1.4 + Devise project, with the following changes:

Steps to reproduce the issue:

  • Create a user (http://localhost:3000/users/sign_up)
  • Sign out (delete cookies?)
  • Try to reset the password (http://localhost:3000/users/password/new)

@tegon

tegon commented Feb 21, 2018

Copy link
Copy Markdown
Member

@jbourassa I get it now, thank you for the test repo, it really helps.
Your building is failing with the same error (ArgumentError: wrong number of arguments (1 for 0)) in some Rails versions, can you take a look at it?

Thanks!

@jbourassa

Copy link
Copy Markdown
Author

This is fixed in Rails 5.1.5 btw.

@rafaelfranca

Copy link
Copy Markdown
Collaborator

Good to know. So I'm closing this PR since it was a bug in the Rails framework.

Thanks

louim added a commit to louim/devise that referenced this pull request May 5, 2023
Rails allow procs and lambda with either zero or more argument. Devise
however always tried to call instance_eval on those values, which does
always pass one argument: self.

There was a PR to fix this specific problem in Devise heartcombo#4627,
before the arity check was fixed in rails itself: rails/rails#30391.

But even if the problem was fixed in Rails, Devise was still calling
the proc/lambas with instance_eval. That meant the fix added to Rails
did not apply to Devise.

The fix is to let Rails handle the :from and :reply_to defaults. We do
that by unsetting the headers instead of trying to replicate Rails handling
in Devise. This lets Rails handle it when setting up the mailer.
rafaelfranca pushed a commit to louim/devise that referenced this pull request Jun 9, 2023
Rails allow procs and lambda with either zero or more argument. Devise
however always tried to call instance_eval on those values, which does
always pass one argument: self.

There was a PR to fix this specific problem in Devise heartcombo#4627,
before the arity check was fixed in rails itself: rails/rails#30391.

But even if the problem was fixed in Rails, Devise was still calling
the proc/lambas with instance_eval. That meant the fix added to Rails
did not apply to Devise.

The fix is to let Rails handle the :from and :reply_to defaults. We do
that by unsetting the headers instead of trying to replicate Rails handling
in Devise. This lets Rails handle it when setting up the mailer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants