DEV: Do not destroy external upload stub on error in debug mode (#14139)

We do not want to destroy the external upload stub records
in debug mode because they allow for investigation of problems
occuring.
This commit is contained in:
Martin Brennan 2021-08-25 11:11:19 +10:00 committed by GitHub
parent e0102a533a
commit d66b258b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -38,6 +38,7 @@ class ExternalUploadStub < ActiveRecord::Base
@statuses ||= Enum.new( @statuses ||= Enum.new(
created: 1, created: 1,
uploaded: 2, uploaded: 2,
failed: 3,
) )
end end

View File

@ -88,7 +88,12 @@ class ExternalUploadManager
# because at this point (calling promote_to_upload!), the multipart # because at this point (calling promote_to_upload!), the multipart
# upload would already be complete. # upload would already be complete.
Discourse.store.delete_file(external_upload_stub.key) Discourse.store.delete_file(external_upload_stub.key)
external_upload_stub.destroy!
if !SiteSetting.enable_upload_debug_mode
external_upload_stub.destroy!
else
external_upload_stub.update(status: ExternalUploadStub.statuses[:failed])
end
raise raise
ensure ensure

View File

@ -127,6 +127,13 @@ RSpec.describe ExternalUploadManager do
expect { subject.promote_to_upload! }.to raise_error(ExternalUploadManager::ChecksumMismatchError) expect { subject.promote_to_upload! }.to raise_error(ExternalUploadManager::ChecksumMismatchError)
expect(ExternalUploadStub.exists?(id: external_upload_stub.id)).to eq(false) expect(ExternalUploadStub.exists?(id: external_upload_stub.id)).to eq(false)
end end
it "does not delete the stub if enable_upload_debug_mode" do
SiteSetting.enable_upload_debug_mode = true
expect { subject.promote_to_upload! }.to raise_error(ExternalUploadManager::ChecksumMismatchError)
external_stub = ExternalUploadStub.find(external_upload_stub.id)
expect(external_stub.status).to eq(ExternalUploadStub.statuses[:failed])
end
end end
end end
@ -146,6 +153,13 @@ RSpec.describe ExternalUploadManager do
"#{upload_base_url}/#{external_upload_stub.key}" "#{upload_base_url}/#{external_upload_stub.key}"
) )
end end
it "does not delete the stub if enable_upload_debug_mode" do
SiteSetting.enable_upload_debug_mode = true
expect { subject.promote_to_upload! }.to raise_error(ExternalUploadManager::SizeMismatchError)
external_stub = ExternalUploadStub.find(external_upload_stub.id)
expect(external_stub.status).to eq(ExternalUploadStub.statuses[:failed])
end
end end
end end