aws / aws-sdk-ruby

The official AWS SDK for Ruby.
https://aws.amazon.com/sdk-for-ruby/
Apache License 2.0
3.57k stars 1.22k forks source link

Aws::S3::Client#delete_object returns an empty delete marker #1396

Closed JanDintel closed 7 years ago

JanDintel commented 7 years ago

Problem When using Aws::S3::Client#delete_object the #delete_marker returns nil, instead of true or false.

Description According to the AWS S3 DELETE Object documentation the delete marker should always return either true or false. However in the Ruby SDK the delete marker returns nil.

Test case You can reproduce the problem with the code below.

require 'securerandom'
require 'aws-sdk'

credentials = Aws::Credentials.new('access_key_id', 'secret_access_key')
client      = Aws::S3::Client.new(region: 'region', credentials: credentials)
bucket      = 'bucket'

test_filename = SecureRandom.uuid
test_data     = 'Hello World!'

put_response = client.put_object(bucket: bucket, key: test_filename, body: test_data) #=> #<struct Aws::S3::Types::PutObjectOutput ... >

get_response = client.get_object(bucket: bucket, key: test_filename) #=> #<struct Aws::S3::Types::GetObjectOutput ... >
get_response.body.read #=> "Hello World!"

delete_response = client.delete_object(bucket: bucket, key: test_filename) #=> #<struct Aws::S3::Types::DeleteObjectOutput ... >
delete_response.delete_marker #=> nil
awood45 commented 7 years ago

We're providing what the service response is providing. It appears that :delete_marker is only ever populated for versioned objects. For example, in a versioned bucket:

s3.put_object(bucket: bucket, key: "test", body: "test")
resp = s3.delete_object(bucket: bucket, key: "test")
resp.delete_marker #=> true

That said, nil is a falsy object, so you should be able to treat it as a boolean.

JanDintel commented 7 years ago

@awood45 I'm sorry, didn't catch that it was only for a versioned object. Thanks for your answer!

danieldcm commented 5 years ago

In case anyone finds this thread from experiencing this issue. I found an interesting fix. If you turn on versioning on the bucket and then turn it back off then the response for delete_marker will return a "true" opposed to a "nil".

I experienced this as I was switching between buckets and had apparently turned on versioning on one bucket and turned it back off while never enabling it on the other bucket.