carrierwaveuploader / carrierwave

Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks
https://github.com/carrierwaveuploader/carrierwave
8.78k stars 1.65k forks source link

recreate_versions!, with fog, errors with undefined method `copy' for nil:NilClass #2739

Open a-aerts opened 2 months ago

a-aerts commented 2 months ago

Hi, I've tried updating Carrierwave from 2.2.6 to 3.0.7, in my code I've got following line: attachment.file.recreate_versions!(:thumb)

It works fine on 2.2.6, on 3.0.7 it raises NoMethodError: undefined method `copy' for nil:NilClass from here: https://github.com/carrierwaveuploader/carrierwave/blob/287e9a1924cbfdf3394b9e23489b98955128aafb/lib/carrierwave/storage/fog.rb#L444

In my case, I've noticed it happening when I'm changing file's name:

      attachment.file.rename(sanitized_file, keep_original: false)
      ThumbsJob.perform_later(attachment.id) if attachment.with_thumb?

Not sure if it's a bug connected to latest fixes regarding recreate_versions and original files, or I'm missing something?

Ruby 3.2.3, Rails 7.1.3.2, fog-aws 3.22.0