-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
rails 7.1 kwargs strategy error #91
Comments
It seems the parameters of controller's constructor before 7.1 is different with the 7.1 one. When using before 7.1, the one Because of this one, this This is new for me, so I don't think I can help to fix this one 😂 |
I still cannot find out how to make this case work, don't you think we should create a strategy and force it to use |
Can you show the stacktrace of the error? module Dummy
def initialize(**kw)
super(**kw)
end
end
class TestController < ActionController::API
include Dummy
include Inject[...]
end I don't have a ready rails project on hands to test it |
I create this test project, so you can have a look at the issue https://github.com/zgid123/test-auto-inject-gem. Full trace ArgumentError (wrong number of arguments (given 1, expected 0)):
actionpack (7.1.2) lib/action_controller/metal.rb:185:in `initialize'
actionpack (7.1.2) lib/action_dispatch/routing/url_for.rb:110:in `initialize'
actionpack (7.1.2) lib/action_controller/metal/url_for.rb:31:in `initialize'
actionpack (7.1.2) lib/action_controller/metal/instrumentation.rb:22:in `initialize'
activerecord (7.1.2) lib/active_record/railties/controller_runtime.rb:20:in `initialize'
dry-auto_inject (1.0.1) lib/dry/auto_inject/strategies/kwargs.rb:68:in `block (2 levels) in define_initialize_with_splat'
dry-auto_inject (1.0.1) lib/dry/auto_inject/strategies/kwargs.rb:19:in `new'
dry-auto_inject (1.0.1) lib/dry/auto_inject/strategies/kwargs.rb:19:in `block (2 levels) in define_new'
actionpack (7.1.2) lib/action_controller/metal.rb:309:in `dispatch'
actionpack (7.1.2) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (7.1.2) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (7.1.2) lib/action_dispatch/journey/router.rb:51:in `block in serve'
actionpack (7.1.2) lib/action_dispatch/journey/router.rb:131:in `block in find_routes'
actionpack (7.1.2) lib/action_dispatch/journey/router.rb:124:in `each'
actionpack (7.1.2) lib/action_dispatch/journey/router.rb:124:in `find_routes'
actionpack (7.1.2) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (7.1.2) lib/action_dispatch/routing/route_set.rb:882:in `call'
rack (3.0.8) lib/rack/etag.rb:29:in `call'
rack (3.0.8) lib/rack/conditional_get.rb:31:in `call'
rack (3.0.8) lib/rack/head.rb:15:in `call'
activerecord (7.1.2) lib/active_record/migration.rb:654:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (7.1.2) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (7.1.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (7.1.2) lib/rails/rack/logger.rb:37:in `call_app'
railties (7.1.2) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (7.1.2) lib/active_support/tagged_logging.rb:135:in `block in tagged'
activesupport (7.1.2) lib/active_support/tagged_logging.rb:39:in `tagged'
activesupport (7.1.2) lib/active_support/tagged_logging.rb:135:in `tagged'
activesupport (7.1.2) lib/active_support/broadcast_logger.rb:240:in `method_missing'
railties (7.1.2) lib/rails/rack/logger.rb:24:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/remote_ip.rb:92:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/request_id.rb:28:in `call'
rack (3.0.8) lib/rack/runtime.rb:24:in `call'
activesupport (7.1.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call'
actionpack (7.1.2) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events'
actionpack (7.1.2) lib/action_dispatch/middleware/server_timing.rb:58:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/static.rb:25:in `call'
rack (3.0.8) lib/rack/sendfile.rb:114:in `call'
actionpack (7.1.2) lib/action_dispatch/middleware/host_authorization.rb:141:in `call'
railties (7.1.2) lib/rails/engine.rb:529:in `call'
puma (6.4.0) lib/puma/configuration.rb:272:in `call'
puma (6.4.0) lib/puma/request.rb:100:in `block in handle_request'
puma (6.4.0) lib/puma/thread_pool.rb:378:in `with_force_shutdown'
puma (6.4.0) lib/puma/request.rb:99:in `handle_request'
puma (6.4.0) lib/puma/server.rb:443:in `process_client'
puma (6.4.0) lib/puma/server.rb:241:in `block in run'
puma (6.4.0) lib/puma/thread_pool.rb:155:in `block in spawn_thread' |
Thanks, so, I had a look and now I don't think it's a bug. Rails now uses dry-auto_inject/spec/integration/kwargs/inheritance/parent_class_injections_spec.rb Lines 70 to 98 in 49516a5
I suggest having a base class as a workaround: class BaseController < ApplicationController
def initialize = super
end
class TestsController < ApplicationController
include Inject[
test_service: 'test_service'
]
def index
test_service.call(test: 'test')
p 'test'
render json: {
message: 'ok'
}
end
end or simply this: class ApplicationController < ActionController::API
def initialize = super
end |
you are correct. When I first upgraded to ruby 3, I changed the parameters to Thank you so much. You saved my day |
Actually, I don't think we can/should fix it, it's not a bug. Instead, we could describe how to set up |
Hi @flash-gordon , I recently upgraded a Rails application to Rails 7 and encountered the same issue. The fix above works. Instead of detecting all pass_through patterns, how about detecting required/optional args/kwargs? Combining this with method arity, I hope we can easily solve the problem of passing on parameters to super_method. If you think that's a good idea, I can make a PR and test it with my application. |
Describe the bug
After upgrade from rails 7.0.8 to 7.1, the
Inject
will raise errorArgumentError (wrong number of arguments (given 1, expected 0))
.After debugging, at this code block
For rails 7.0.8's controller, the
super_parameters
is notsplat
orsequential_arguments
, but rails 7.1 will be.I am still not understand what the problem is. I will try to debug and find out problem.
To Reproduce
Use the code above using rails 7.1
Expected behavior
Can inject the service
My environment
The text was updated successfully, but these errors were encountered: