Background Job atomic_promote argument error
darkisa opened this issue · comments
Brief Description
When I call attacher.atomic_promote
in a background job, I get an ArgumentError: wrong number of arguments (given 1, expected 0)
Expected behavior
I expect the atomic_promote
command to succeed
Actual behavior
ArgumentError: wrong number of arguments (given 1, expected 0)
Simplest self-contained example code to demonstrate issue
Initializer:
require "shrine"
require "shrine/storage/s3"
Shrine.storages = {
cache: Shrine::Storage::S3.new(prefix: 'cache', **Rails.configuration.storage),
store: Shrine::Storage::S3.new(public: true, **Rails.configuration.storage)
}
Shrine.plugin :activerecord # loads Active Record integration
Shrine.plugin :cached_attachment_data # enables retaining cached file across form redisplays
Shrine.plugin :restore_cached_data # extracts metadata for assigned cached files
Shrine.plugin :backgrounding
Uploader:
class ImageUploader < Shrine
plugin :derivatives
Attacher.derivatives do |original|
magick = ImageProcessing::MiniMagick.source(original)
{
large: magick.resize_to_limit!(800, 800),
medium: magick.resize_to_limit!(500, 500),
small: magick.resize_to_limit!(300, 300)
}
end
Attacher.promote_block do
PromoteImageJob.perform_async(self.class.name, record.class.name, record.id, name, file_data)
end
Attacher.destroy_block do
DestroyImageJob.perform_async(self.class.name, data)
end
def generate_location(io, record: nil, derivative: nil, **)
...
end
end
Controller:
class ImagesController < ApplicationController
def update
performance.update!(image: params[:image])
render json: serialize(performance, type: :performance)
end
end
Worker:
class PromoteImageJob
include Sidekiq::Worker
def perform(attacher_class, record_class, record_id, name, file_data)
attacher_class = Object.const_get(attacher_class)
record = Object.const_get(record_class).find(record_id)
attacher = attacher_class.retrieve(model: record, name: name, file: file_data)
attacher.create_derivatives
attacher.atomic_promote # Error happens here
rescue Shrine::AttachmentChanged, ActiveRecord::RecordNotFound
...
end
end
System configuration
Ruby version: 2.6.4
Shrine version: 3.2.1
Could you include the backtrace of the exception?
Thanks for the quick response @janko and great product. I have added a screenshot of the backtrace where the error occurs.
@darkisa My guess is that you've overriding the #reload
method on the Performance
model, but are not passing parameters through. Shrine calls reload(lock: true)
on the model, so if your override isn't accepting arguments, that would cause the error.
shrine/lib/shrine/plugins/activerecord.rb
Line 108 in ad65741
That's it! I did override the default reload
method a while back and never thought to look there. It's been solved by adding reload(**options)
to my custom reload
method. Thank you for your time!