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

regression with 2.5.1: ArgumentError: unknown keyword #1444

Closed
rocket-turtle opened this issue Aug 11, 2022 · 5 comments · Fixed by #1445
Closed

regression with 2.5.1: ArgumentError: unknown keyword #1444

rocket-turtle opened this issue Aug 11, 2022 · 5 comments · Fixed by #1445

Comments

@rocket-turtle
Copy link

Basic Info

  • Faraday Version: faraday-2.5.1
  • Ruby Version: ruby-2.7.6

Issue description

With the new Version I get an ruby deprecation and my test is failing:

../faraday-2.5.1/lib/faraday/adapter/test.rb:287: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
../faraday-2.5.1/lib/faraday/adapter.rb:62: warning: The called method `save_response' is defined here
    returns a predefined response (FAILED - 1)

Failures:

  1) Test::Client#disabled_api_connection returns a predefined response
     Failure/Error: response = connection.get('')

     ArgumentError:
       unknown keyword: :"Content-Type"
     # ../faraday-2.5.1/lib/faraday/adapter.rb:62:in `save_response'
     # ../faraday-2.5.1/lib/faraday/adapter/test.rb:287:in `call'
     # ../faraday-2.5.1/lib/faraday/rack_builder.rb:153:in `build_response'
     # ../faraday-2.5.1/lib/faraday/connection.rb:445:in `run_request'
     # ../faraday-2.5.1/lib/faraday/connection.rb:200:in `get'
     # ../spec/models/test/client_spec.rb:323:in `block (3 levels) in <top (required)>'

I think the Problem is that 6799f58 added an keyword parameter to save_response and now the headers from lib/faraday/adapter.rb:62 are splitted into the arguments and cause the Problem.

Steps to reproduce

I do not know why the tests for the Adapter do not show the same error. I can investigate further if you can not reproduce the error.

@iMacTia
Copy link
Member

iMacTia commented Aug 11, 2022

Thanks for reporting this @rocket-turtle, I'm taking a look 👍

@iMacTia
Copy link
Member

iMacTia commented Aug 11, 2022

For starters, I can now tell why this was not captured by tests:

# this works as expected
save_response(env, 200, 'test', {'test' => 'test'})

# this raises an unknown keyword: :test error
save_response(env, 200, 'test', {test: 'test'})

It turns out, Ruby 2.7 will attempt to use the last hash argument as kwargs only if the keys are symbols

@iMacTia
Copy link
Member

iMacTia commented Aug 11, 2022

I've merged a fix and will soon release this as v2.5.2 👍

@rocket-turtle
Copy link
Author

Thank you for the fast fix.

It turns out, Ruby 2.7 will attempt to use the last hash argument as kwargs only if the keys are symbols

That is interesting.
Lets hope no other Adapter uses save_response with a Symbole Hash

@iMacTia
Copy link
Member

iMacTia commented Aug 11, 2022

I actually checked all the known adapters (at least those documented in awesome-faraday), and since they all support the reason_phrase, they should all be unaffected 👍 (as reason_phrase will act as a separator between headers and kwargs)

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

Successfully merging a pull request may close this issue.

2 participants