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

Rails 7.1 after commit callback order #2713

Closed codez closed 7 months ago

codez commented 7 months ago

Rails 7.1 has a new default that runs after_commit callbacks in the order they are defined.

new_framework_defaults_7_1.rb:

# Run `after_commit` and `after_*_commit` callbacks in the order they are defined in a model.
# This matches the behaviour of all other callbacks.
# In previous versions of Rails, they ran in the inverse order.
#++
Rails.application.config.active_record.run_after_transaction_callbacks_in_order_defined = true

This causes previously stored files not to be removed when they are updated, because after_commit :"remove_previously_stored_#{column}", on: :update runs after after_commit :"reset_previous_changes_for_#{column}" (which resets the @removed_uploaders).

As a workaround, the above configuration can be set to false, but it would be nice if carrierwave could handle this. Probably it's enough to check the configuration and define the callbacks the other way around.

mshibuya commented 7 months ago

Thank you for reporting, now fixed in the master!

codez commented 7 months ago

Great, thank you very much for the quick fix!