FIX: Address ArgumentError: wrong number of arguments (given 4, expected 3) (PR #14444)

This pull request addresses ArgumentError: wrong number of arguments (given 4, expected 3) to support Ruby 3 keyword arguments.

Steps to reproduce

% ruby -v                                                                                                                                                                                                                                  ruby3
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin21]
% bundle exec rails server

Expected result

It should run without errors.

Actual result

It gets ArgumentError: wrong number of arguments (given 4, expected 3) when calling zrange method.

2021-09-27T03:12:23.255Z pid=42543 tid=17hb WARN: {"current_db":"default","current_hostname":"localhost","message":"While ticking scheduling manager"}
2021-09-27T03:12:23.255Z pid=42543 tid=17hb WARN: ArgumentError: wrong number of arguments (given 4, expected 3)
2021-09-27T03:12:23.255Z pid=42543 tid=17hb WARN: /Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/redis-4.4.0/lib/redis.rb:1784:in `zrange'
/Users/yahonda/src/github.com/discourse/discourse/lib/discourse_redis.rb:68:in `public_send'
/Users/yahonda/src/github.com/discourse/discourse/lib/discourse_redis.rb:68:in `block (3 levels) in <class:DiscourseRedis>'
/Users/yahonda/src/github.com/discourse/discourse/lib/discourse_redis.rb:29:in `ignore_readonly'
/Users/yahonda/src/github.com/discourse/discourse/lib/discourse_redis.rb:68:in `block (2 levels) in <class:DiscourseRedis>'
/Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mini_scheduler-0.13.0/lib/mini_scheduler/manager.rb:279:in `schedule_next_job'
/Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mini_scheduler-0.13.0/lib/mini_scheduler/manager.rb:273:in `block in tick'
/Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mini_scheduler-0.13.0/lib/mini_scheduler/manager.rb:323:in `block in lock'
/Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mini_scheduler-0.13.0/lib/mini_scheduler/distributed_mutex.rb:46:in `synchronize'
/Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mini_scheduler-0.13.0/lib/mini_scheduler/distributed_mutex.rb:14:in `synchronize'
/Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mini_scheduler-0.13.0/lib/mini_scheduler/manager.rb:322:in `lock'
/Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mini_scheduler-0.13.0/lib/mini_scheduler/manager.rb:272:in `tick'
/Users/yahonda/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/mini_scheduler-0.13.0/lib/mini_scheduler.rb:71:in `block (2 levels) in start'
Job exception: wrong number of arguments (given 4, expected 3)

Additional information.

When args is like this, it gets the ArgumentError.

  • args
["default:_scheduler_queue_default_", 0, 0, {:withscores=>true}]

The zrange method signature is:

def zrange(key, start, stop, withscores: false, with_scores: withscores)
...
end

GitHub

The title of this pull request changed from “Address ArgumentError: wrong number of arguments (given 4, expected 3)” to "FIX: Address ArgumentError: wrong number of arguments (given 4, expected 3)

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

Sorry, this fix is too messy, instead we should explicitly patch zrange

Thanks for the review. I understand this pull request looks dirty.

Does explicitly patch zrange mean that opening a pull request to change the method signature at redis/redis-rb repository?

Or kind of monkey-patching zrange inside of discourse/discourse repository?

I have reverted the original commit and made a better fix.

kind of monkey-patching zrange inside of discourse/discourse repository?

Yup this is what @SamSaffron meant. See https://github.com/discourse/discourse/blob/cd64e887118819476507950f01ac24fba91bef8a/lib/discourse_redis.rb#L63-L83 for some examples :slight_smile:

I have reverted the original commit and made a better fix.

This looks good to me :+1: Thank you for your contribution :+1: