carrierwaveuploader / carrierwave

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

3.0.2 breaks uploader behavior with rollback and deletes files in remote #2685

Closed rajyan closed 1 year ago

rajyan commented 1 year ago

Description

From 3.0.2, carrierwave started to delete files in remote when rollback happens. (which causes a 404 link)

I haven't found the root cause yet, but confirmed that it doesn't happen in 3.0.1.

Still looking for the cause in https://github.com/carrierwaveuploader/carrierwave/pull/2679

sample code

ActiveRecord::Base.transaction do
  vals.map do |val, i|
    attachment = post.attachments.find(val["id"])
    attachment.some_column = val["col"] # not the mounted column
    attachment.save!
  end
end

post model has a has_many association with attachment model, which mounts a uploader. when the transaction is rolled back by find or save!, file is deleted for attachment that is saved in the previous iteration.

rajyan commented 1 year ago

I'm trying to create a failing test case right now.

rajyan commented 1 year ago

I'm trying to create a failing test case right now.

Done. https://github.com/carrierwaveuploader/carrierwave/pull/2686

rajyan commented 1 year ago

@mshibuya

Could you please cut a new release? Although we have reverted to 3.0.1 and not affected by this issue now, I believe this issue seems quite critical, because it might delete users files in remote.

mshibuya commented 1 year ago

You're right, just released 3.0.3.

rajyan commented 1 year ago

Thank you!