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

CurrentAttributes middleware fails (required keyword: with) #5048

Closed
mhenrixon opened this issue Nov 6, 2021 · 5 comments
Closed

CurrentAttributes middleware fails (required keyword: with) #5048

mhenrixon opened this issue Nov 6, 2021 · 5 comments

Comments

@mhenrixon
Copy link
Contributor

mhenrixon commented Nov 6, 2021

Ruby version: 3.0.2
Rails version: 7.0.0-rc2 (rails/rails:master)
Sidekiq / Pro / Enterprise version(s): sidekiq-6.3.0

Please include your initializer, sidekiq.yml, and any error message with the full backtrace.

require "sidekiq/job"
require "sidekiq/middleware/current_attributes"

ActiveSupport::Reloader.to_prepare do
  Sidekiq::CurrentAttributes.persist(SidekiqCurrent)
end
ArgumentError:
       wrong number of arguments (given 1, expected 0; required keyword: with)
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/middleware/current_attributes.rb:18:in `initialize'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/middleware/chain.rb:158:in `new'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/middleware/chain.rb:158:in `make_new'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/middleware/chain.rb:76:in `each'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/middleware/chain.rb:76:in `each'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/middleware/chain.rb:125:in `map'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/middleware/chain.rb:125:in `retrieve'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/middleware/chain.rb:135:in `invoke'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/client.rb:217:in `process_single'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/client.rb:71:in `push'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/worker.rb:307:in `client_push'
     # ./vendor/bundle/ruby/3.0.0/gems/sidekiq-6.3.0/lib/sidekiq/worker.rb:241:in `perform_async'
     # ./app/controllers/webhooks/stripe_controller.rb:22:in `queue_event'
     # ./app/controllers/webhooks/stripe_controller.rb:8:in `create'

I think this might be a ruby 3 problem and you can easily reproduce it with:

pry(main)> def compute(with:)
pry(main)*   puts "This won't be reached"
pry(main)* end
pry(main)> compute(*[{with: "bogus"}])
ArgumentError: wrong number of arguments (given 1, expected 0; required keyword: with)

pry(main)> compute(*{with: "bogus"})
ArgumentError: wrong number of arguments (given 1, expected 0; required keyword: with)
from (pry):1:in `compute'

But this does work:

pry(main)> compute(**{with: "bogus"})
This won't be reached
@mperham
Copy link
Collaborator

mperham commented Nov 6, 2021

I’m not sure of the fix but keyword args are definitely not required here; we could change the middleware to just use a normal arg.

@mperham
Copy link
Collaborator

mperham commented Nov 6, 2021

Not sure how this test passed on Ruby 3…

https://github.com/mperham/sidekiq/blob/62efdd1ba23c8cac5f6b7c715bc7d525323306bd/test/test_current_attributes.rb#L34

@mhenrixon
Copy link
Contributor Author

The beauty with dynamic (scripting) languages is that you never know what you get.

Wonder if it is something about ruby on Mac vs ruby on Linux?

@mperham
Copy link
Collaborator

mperham commented Nov 7, 2021

I've got the test failing now and am working on the fix.

@mperham
Copy link
Collaborator

mperham commented Nov 7, 2021

Fixed on main, I'll release tomorrow.

@mperham mperham closed this as completed Nov 7, 2021
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

2 participants