Skip to content

Mounted uploaders may not remove file on object storage when destroyed

Summary

The mounted uploaders use the Upload.store attribute to know where the file is stored.

On some models, the Upload relationship is declared as dependent: :destroy which causes the child Uploads to be destroyed before CarrierWave's destroy hook, which will cause CarrierWave to not be able to properly remove the file.

Steps to reproduce

You need to configure Object Storage on your environment: https://docs.gitlab.com/ee/administration/uploads.html#using-object-storage

FactoryBot.create(:appearance, :with_logos)
Appearance.first.logo.migrate!(ObjectStorage::Store::REMOTE)
Appearance.first.destroy

The logo will still be stored on Object Storage.

What is the expected correct behavior?

The file should be deleted.

Possible fixes

  • Remove the dependent: :destroy relationships for the Upload model then enqueue a job that does

/cc @ayufan @smcgivern

Edited by Micaël Bergeron