Ruby 3.0.3 kwargs error
wuarmin opened this issue · comments
Describe the bug
If I use hanami-controller 1.3.3
with dry-aut_inject 0.7(8 and 9)
with ruby 3.0.0
module Controllers
module Graphql
class Endpoint
include Hanami::Action
include Import[:service]
def call(params)
self.format = :json
query = params.get(:query)
graphql_response = service.execute(query)
status 200, graphql_response.to_json
end
end
end
end
I get following error:
Failure/Error: response = subject.call(**params)
ArgumentError:
wrong number of arguments (given 1, expected 0)
# /usr/local/bundle/gems/dry-auto_inject-0.9.0/lib/dry/auto_inject/strategies/kwargs.rb:48:in `block (2 levels) in define_initialize_with_keywords'
# /usr/local/bundle/gems/hanami-controller-1.3.3/lib/hanami/action/rack.rb:179:in `initialize'
# /usr/local/bundle/gems/hanami-controller-1.3.3/lib/hanami/action/mime.rb:214:in `initialize'
# /usr/local/bundle/gems/dry-auto_inject-0.9.0/lib/dry/auto_inject/strategies/kwargs.rb:22:in `new'
# /usr/local/bundle/gems/dry-auto_inject-0.9.0/lib/dry/auto_inject/strategies/kwargs.rb:22:in `block (2 levels) in define_new'
# ./spec/controllers/graphql/endpoint_spec.rb:18:in `block (3 levels) in <top (required)>
To Reproduce
Use ruby >= 3.0.3
hanami-controller 1.3.3
with dry-aut_inject 0.7(8 and 9)
and import a dependency with default strategy into a Hanami::Action
Expected behavior
The Hanami Action should be instantiated properly.
My environment
ruby:3.0.3-slim-buster
Methods from Hanami don't seem to accept keywords https://github.com/hanami/controller/blob/v1.3.3/lib/hanami/action/mime.rb#L213. You need to either patch them (better) or use a different injection strategy (worse).
For example, in Ruby 3 you can use ...
:
module Hanami
module Action
# Mime type API
#
# @since 0.1.0
#
# @see Hanami::Action::Mime::ClassMethods#accept
module Mime
module InstanceMethods
def initialize(...)
super
@content_type = nil
@charset = nil
end
end
end
end
end
Same will be required for action/rack.rb
. Of course, you can send a PR to Hanami but I'm not sure if 1.x supports ruby 3+.
Understood.
Thanks!