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,8 +14,10 @@ module Packages
artifact.destroy!
rescue StandardError
unless artifact&.destroyed?
artifact&.update_column(:status, :error)
end
end
after_destroy
end
......
......@@ -43,9 +43,10 @@ RSpec.describe Packages::CleanupPackageFileWorker do
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) }
context 'with an error during the destroy' do
before do
expect(worker).to receive(:log_metadata).and_raise('Error!')
end
......@@ -56,6 +57,25 @@ RSpec.describe Packages::CleanupPackageFileWorker do
end
end
context 'when trying to destroy a destroyed record' do
before do
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
context 'removing the last package file' do
let_it_be(:package_file) { create(:package_file, :pending_destruction, package: package) }
......
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