diff options
author | Jasper Martin <jaspervanbrianmartin@gmail.com> | 2018-07-26 21:24:31 +0800 |
---|---|---|
committer | George Claghorn <george.claghorn@gmail.com> | 2018-07-26 09:24:31 -0400 |
commit | 934fccd5223ae41f3f1cc7d548af509302f64828 (patch) | |
tree | b4ed89df2087796fa7cbeb139803efda693ae154 /activestorage/app | |
parent | 8a5fe2bcded1468934f060666a69dcd7d1fac9ae (diff) | |
download | rails-934fccd5223ae41f3f1cc7d548af509302f64828.tar.gz rails-934fccd5223ae41f3f1cc7d548af509302f64828.tar.bz2 rails-934fccd5223ae41f3f1cc7d548af509302f64828.zip |
Ignore ActiveRecord::InvalidForeignKey in ActiveStorage::Blob#purge
Do nothing instead of raising an error when it’s called on an attached blob.
Diffstat (limited to 'activestorage/app')
-rw-r--r-- | activestorage/app/jobs/active_storage/purge_job.rb | 2 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/blob.rb | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/activestorage/app/jobs/active_storage/purge_job.rb b/activestorage/app/jobs/active_storage/purge_job.rb index b021b5f2d0..fa15e0451d 100644 --- a/activestorage/app/jobs/active_storage/purge_job.rb +++ b/activestorage/app/jobs/active_storage/purge_job.rb @@ -2,7 +2,7 @@ # Provides asynchronous purging of ActiveStorage::Blob records via ActiveStorage::Blob#purge_later. class ActiveStorage::PurgeJob < ActiveStorage::BaseJob - discard_on ActiveRecord::RecordNotFound, ActiveRecord::InvalidForeignKey + discard_on ActiveRecord::RecordNotFound def perform(blob) blob.purge diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb index bf87598a66..e7f2615b0f 100644 --- a/activestorage/app/models/active_storage/blob.rb +++ b/activestorage/app/models/active_storage/blob.rb @@ -207,6 +207,7 @@ class ActiveStorage::Blob < ActiveRecord::Base def purge destroy delete + rescue ActiveRecord::InvalidForeignKey end # Enqueues an ActiveStorage::PurgeJob to call #purge. This is the recommended way to purge blobs from a transaction, |