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

Delayed methods with kwargs not working using ruby 3.0.0 #1134

Closed
chbach opened this issue Jan 5, 2021 · 11 comments
Closed

Delayed methods with kwargs not working using ruby 3.0.0 #1134

chbach opened this issue Jan 5, 2021 · 11 comments

Comments

@chbach
Copy link

chbach commented Jan 5, 2021

I recently upgraded our rails app to 6.1 running on ruby 3.0.0. I have now several parts of my code failing when calling methods with keyword arguments (or named parameters) in conjunction with delay. I can reproduce the issue in the rails console:

def my_delayed_method(foo:, bar:) puts foo, bar end
=> :my_delayed_method

my_delayed_method(foo: 'foo', bar: 'bar')
foo
bar
=> nil

delay.my_delayed_method(foo: 'foo', bar: 'bar')
Traceback (most recent call last):
        2: from (irb):4:in `<main>'
        1: from (irb):1:in `my_delayed_method'
ArgumentError (wrong number of arguments (given 1, expected 0; required keywords: foo, bar))

I think this has something to do with the separation of args and kwargs introduced in ruby 2.7. Does delayed_job support ruby 3 and I am missing something? Or is this a compatibility issue?

Rails Version: 6.1.0
Ruby Version: 3.0.0
Delayed Job Version:
delayed_job_active_record (4.1.5)
delayed_job (4.1.9)

@csuhta
Copy link

csuhta commented Jan 25, 2021

Also encountering this issue, a backtrace is provided. Looks like #1130 has some progress on this already

app/models/<removed>/image_methods.rb:35:in `update_images_and_upsert!': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/performable_method.rb:26:in `perform'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/backend/base.rb:81:in `block in invoke_job'
    from vendor/bundle/ruby/3.0.0/gems/bugsnag-6.19.0/lib/bugsnag/integrations/delayed_job.rb:30:in `block (2 levels) in <class:Bugsnag>'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:61:in `block in initialize'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:79:in `block in add'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:66:in `execute'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:40:in `run_callbacks'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/backend/base.rb:78:in `invoke_job'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/worker.rb:230:in `block (2 levels) in run'
    from vendor/ruby-3.0.0/lib/ruby/3.0.0/timeout.rb:97:in `block in timeout'
    from vendor/ruby-3.0.0/lib/ruby/3.0.0/timeout.rb:107:in `timeout'
    from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/worker.rb:230:in `block in run'
    from vendor/ruby-3.0.0/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
    [...]

@chbach
Copy link
Author

chbach commented Jan 25, 2021

Yes, with #1130 it seems to work.

@jacobjlevine
Copy link

Waiting on this, as well!

@jacobjlevine
Copy link

@albus522 it looks like you're one of the primary caretakers of this gem. There are a couple of proposed PRs that would supposedly make DelayedJob compatible with Ruby 3. Any chance we can get your involvement to help move forward with at least one of the proposed solutions?

@jacobjlevine
Copy link

Hey @albus522! So sorry to bother you again. Any chance we could get your eyes on this?

tomhughes added a commit to openstreetmap/chef that referenced this issue Jul 22, 2022
The mail jobs are affected by a ruby 3 compatibility issue in
the DelayedJob gem:

collectiveidea/delayed_job#1134
tomhughes added a commit to tomhughes/openstreetmap-website that referenced this issue Jul 23, 2022
The delayed_job gem does not currently perserve keyword arguments
properly leading to errors when running under ruby 3 and try to run
a job that requires them.

This affects our deferred mail deliveries so we monkey patch the
mail delivery job to unpack the hash from the normal arguments and
use it to provide the expected keyword arguments.

collectiveidea/delayed_job#1134
tomhughes added a commit to openstreetmap/openstreetmap-website that referenced this issue Jul 23, 2022
The delayed_job gem does not currently perserve keyword arguments
properly leading to errors when running under ruby 3 and try to run
a job that requires them.

This affects our deferred mail deliveries so we monkey patch the
mail delivery job to unpack the hash from the normal arguments and
use it to provide the expected keyword arguments.

collectiveidea/delayed_job#1134
@exit-only
Copy link

Ruby 2.7 is EOL on March 31st and this is still broken which is a shame. It has been an obstacle in upgrading services to ruby 3x. There are a number of PRs addressing this issue, which can be leveraged but it would be nice to have an officially supported fix in.

https://endoflife.date/ruby

@albus522
Copy link
Member

Keyword arguments have a lot of hidden complexity to implement for a background task which is why background job libraries are opting not to support them. This is not a ruby 2.7 compatibility thing. It is a complex ongoing support thing.

I don't expect Delayed Job will be adding support for this.

@exit-only
Copy link

ok good to know. thanks!

@synth
Copy link

synth commented Sep 17, 2023

Well, this is a sad discovery during an upgrade process. I'd like to learn more about other the other bg job libraries that are having issues or the specific issues in delayed_job. Having a bg job library not support kwargs isn't stellar for developer experience.

Also, it seems Betterment's delayed gem has taken up the torch and supports kwargs for those who don't want to revert to positional args.

In any case, much gratitude to the delayed_job contribs, we've relied on this library for a long time. Thank you :)

@brettchalupa
Copy link

I noticed this was closed as completed but I'm still experiencing the issue when upgrading a codebase from Ruby 2.7 to Ruby 3.1 with delayed_job's handle_asyncronously for methods using keyword args. I don't see any obvious commits or an entry in the CHANGELOG about how this was fixed. Is this actually fixed or was it accidentally closed? Thanks!

@chbach
Copy link
Author

chbach commented Nov 26, 2024

It has never been fixed @brettchalupa

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

7 participants