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

ActiveJob should support passing of keyword arguments to perform method #18741

threadhead opened this issue Jan 30, 2015 · 5 comments


Copy link

threadhead commented Jan 30, 2015

Since Rails 5+ will required Ruby 2.2+, ActiveJob should support the passing of keyword arguments to the perform method.

class MyAwesomeJob < ActiveJob::Base
  def perform(ginger_ninjas: 1)

MyAwesomeJob.perform_later(ginger_ninjas: 5)

Currently (rails 4.2), you get a ArgumentError: wrong number of arguments (1 for 0) if you try to pass keyword arguments.

@sgrif sgrif added this to the 4.2.1 milestone Jan 30, 2015
Copy link

sgrif commented Jan 30, 2015

This appears to be due to the hash getting converted to string keys during job serialization/deserialization, while keyword arguments only work with symbol keyed hashes.

sgrif added a commit that referenced this issue Jan 30, 2015
Unfortunately, the HashWithIndifferent access approach is insufficient
for our needs. It's perfectly reasonable to want to use keyword
arguments with Active Job, which we will see as a symbol keyed hash. For
Ruby to convert this back to keyword arguments, it must deserialize to a
symbol keyed hash.

There are two primary changes to the serialization behavior. We first
treat a HWIA separately, and mark it as such so we can convert it back
into a HWIA during deserialization.

For normal hashes, we keep a list of all symbol keys, and convert them
back to symbol keys after deserialization.

Fixes #18741.

@sgrif sgrif closed this as completed in 31085a5 Jan 30, 2015
Copy link

sgrif commented Jan 30, 2015

Backported in 31085a5

Copy link

threadhead commented Jan 30, 2015

@sgrif Impressive. I was going to start hacking on it after I got back from lunch, but you beat me to it. Thank you.

tgxworld added a commit to ruby-bench/ruby-bench-web that referenced this issue Feb 13, 2015
Copy link

chrisnicola commented Feb 18, 2016

This is awesome. I was testing it out with Ruby 4.2.4 and noticed that if you mix keyword and regular arguments it doesn't work. For example:

perform(message, channel: '#default')

Won't work and gives you a ArgumentError: wrong number of arguments (2 for 1) error.

perform(message:, channel: '#default')


Copy link

mosesliao commented May 4, 2018

curious, can I use it for perform_later??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

4 participants