Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

With Ruby 3.0 validator produces "ArgumentError: wrong number of arguments (given 3, expected 1..2)" #2673

Open
vtamara opened this issue Feb 23, 2021 · 6 comments

Comments

@vtamara
Copy link

vtamara commented Feb 23, 2021

The regression tests of an open source rails engine called sip, that uses paperclip, work good with Ruby 2.7 as can be seen at:
https://travis-ci.org/github/pasosdeJesus/sip/jobs/760216853

However with Ruby 3.0 the following errors appear (as can be seen at https://travis-ci.org/github/pasosdeJesus/sip/jobs/760216854#L976):

1) Error:

Sip::AnexoTest#test_no_valido_1:

ArgumentError: wrong number of arguments (given 3, expected 1..2)

    /home/travis/build/pasosdeJesus/sip/vendor/bundle/ruby/3.0.0/gems/activemodel-6.1.3/lib/active_model/errors.rb:404:in `add'

    /home/travis/build/pasosdeJesus/sip/vendor/bundle/ruby/3.0.0/gems/paperclip-6.1.0/lib/paperclip/validators/attachment_presence_validator.rb:8:in `validate_each'
...

and

2) Error:

Sip::AnexoTest#test_no_valido_2:

ArgumentError: wrong number of arguments (given 3, expected 1..2)

    /home/travis/build/pasosdeJesus/sip/vendor/bundle/ruby/3.0.0/gems/activemodel-6.1.3/lib/active_model/errors.rb:404:in `add'

    /home/travis/build/pasosdeJesus/sip/vendor/bundle/ruby/3.0.0/gems/paperclip-6.1.0/lib/paperclip/validators/attachment_presence_validator.rb:8:in `validate_each'
...

Both are related to expressions anexo.valid? where anexo is amodel with a paperclip attachment. Both use the validator AttachmetntPresenceValidator that includes the statement producing the error:

def validate_each(record, attribute, value)
    if record.send("#{attribute}_file_name").blank?
      record.errors.add(attribute, :blank, *options)
    end
end  
@gdonald
Copy link

gdonald commented Jan 30, 2022

I'm hitting this same issue with Ruby 3.1.0. Any ETA on the fix?

@vtamara
Copy link
Author

vtamara commented Mar 23, 2022

I switch to kt-paperclip

@joshuapinter
Copy link

I concur. I switched to kt-paperclip and it's the way to go for Ruby 3+ support as well as ongoing maintenance. We had to update our WebMock and specs a bit as there were some changes in how files are requested from AWS in kt-paperclip but otherwise, seamless transition.

@maxvlc
Copy link

maxvlc commented Sep 12, 2022

The thing is that I also need 'paperclip-optimizer' which seems that install original paperclip
I installed kt-paperclip-optimizer, but it also install in the background original paperclip gem, which causes that error:

ArgumentError:
       wrong number of arguments (given 3, expected 1..2

That's a part of my Gemfile.lock where is installed paperclip

    paperclip (6.1.0)
      activemodel (>= 4.2.0)
      activesupport (>= 4.2.0)
      mime-types
      mimemagic (~> 0.3.0)
      terrapin (~> 0.6.0)
    paperclip-optimizer (2.0.0)
      image_optim (~> 0.19)
      paperclip (>= 3.4)

Someone knows how to avoid that dependency and just keep installed kt-paperclip¿?

@joshuapinter
Copy link

@maxvlc Can you not just fork the project and update the dependency in the .gemspec file?

@maxvlc
Copy link

maxvlc commented Sep 13, 2022

@maxvlc Can you not just fork the project and update the dependency in the .gemspec file?

@joshuapinter Yep, that's the point, fork the gem and keep it on our project.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants