Shrine promote behaviour when the file isn't available

Hi, what’s the intended behaviour of Shrine::Attacher.promote(data) if the given file isn’t available (or doesn’t exist)?

It seems like it just returns nil instead of raising an exception?

For context, I’m using Shrine 2.19.3 with S3 storage and the backgrounding plugin.

Hi, the Attacher.promote method will “abort” for two reasons:

  • the attachment has changed on the original record
  • the record was deleted

In Shrine 2.x it will unfortunately just return nil, not giving you an option to handle the scenario. I’ve eventually realized the shortcomings of this, so in Shrine 3.x I’ve rewritten the backgrounding plugin, and there exceptions will be raised for both cases (Shrine::AttachmentChanged or ActiveRecord::RecordNotFound). In general, the new backgrounding API is much more explicit, so you’ll have more control.

I’ve recently released 3.0.0.rc, and I’m encouraging people to try it out. Lots of things changed since 2.19, namely several plugins have been removed/deprecated, and Attacher and backgrounding have been rewritten. But in general there are big improvements in design and flexibility, and I’ve written detailed release notes and upgrading guide that should hopefully ease the transition.