Commit 6e29a3cb authored by David Fernandez's avatar David Fernandez

Do not try to update a deleted record

We can have errors once the record is deleted and the current error
handling will try to update the record. That update should go through
only if the record is not deleted.

Changelog: fixed
parent 6e8b14bd
...@@ -14,7 +14,9 @@ module Packages ...@@ -14,7 +14,9 @@ module Packages
artifact.destroy! artifact.destroy!
rescue StandardError rescue StandardError
artifact&.update_column(:status, :error) unless artifact&.destroyed?
artifact&.update_column(:status, :error)
end
end end
after_destroy after_destroy
......
...@@ -43,16 +43,36 @@ RSpec.describe Packages::CleanupPackageFileWorker do ...@@ -43,16 +43,36 @@ RSpec.describe Packages::CleanupPackageFileWorker do
end end
end end
context 'with an error during the destroy' do context 'with a package file to destroy' do
let_it_be(:package_file) { create(:package_file, :pending_destruction) } let_it_be(:package_file) { create(:package_file, :pending_destruction) }
before do context 'with an error during the destroy' do
expect(worker).to receive(:log_metadata).and_raise('Error!') before do
expect(worker).to receive(:log_metadata).and_raise('Error!')
end
it 'handles the error' do
expect { subject }.to change { Packages::PackageFile.error.count }.from(0).to(1)
expect(package_file.reload).to be_error
end
end end
it 'handles the error' do context 'when trying to destroy a destroyed record' do
expect { subject }.to change { Packages::PackageFile.error.count }.from(0).to(1) before do
expect(package_file.reload).to be_error allow_next_found_instance_of(Packages::PackageFile) do |package_file|
destroy_method = package_file.method(:destroy!)
allow(package_file).to receive(:destroy!) do
destroy_method.call
raise 'Error!'
end
end
end
it 'handles the error' do
expect { subject }.to change { Packages::PackageFile.count }.by(-1)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment