Indirect derivatives

I spent the better part of yesterday trying to figure this out. We have an external process that does all of our file manipulation. This process is kicked off via rabbitmq, saves a file to disk and then fires a completion event. There are many different processes kicked off in an activerecord commit callback for each derivative and none of them are guaranteed to exist, or be ready at the same time. From there I want to inject them into the derivatives for the uploader. I tried a few ways via the attacher and ended up with a correct image_data column on my record. However, when trying to access those derivatives via record.image_url(<name>) I was met with a nil response.

We tried via add_derivative, create_derivative, and merge_derivatives with no luck. What could i be missing? Here is the call to save one of them

def insert_mosaic_derivative
  Design.find(payload[:object_id]).tap do |design|
    source_file =
    tmp_file = source_file.dirname.join('mosaic.png')
    attacher = design.image_attacher


    design.update!(ready: true)

The uploader itself only has the derivatives plugin.


A quick mention here that before saving the record the derivative is available via the url call. After saving and calling reload or re-fetching from the database the derivative, while still in the image_data column, is not avilable.

So this appears to be isolated to rspec. We’re using database cleaner, but specifically in truncation mode for this example. When running all of this via the rails console it works as expected.

We JUST figured out why this happened. In one of our tests we had Shrine.plugin :derivatives. This was modifying the global Shrine object and causing things to blow up.


1 Like