Description
Describe the bug
Hi,
I recently noticed rather inconsistent behavior while using DeleteObjects
command.
Example scenario: Sending DeleteObjects
request where one of the files has invalid key (too long in my case). The client throws AmazonS3Exception
where I believe the DeleteObjectsException
should be thrown instead. Moreover the valid object keys listed in the request are not deleted.
I haven't seen any remarks for this particular case in the documentation to this method.
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
When one of the keys is invalid the DeleteObjectsException
should be thrown and the objects under valid keys should be deleted.
Current Behavior
When one of the keys is invalid the AmazonS3Exception
is thrown and none of the objects is deleted.
Reproduction Steps
See this little sample which reproduces the problem:
// upload valid object
var content = Guid.NewGuid().ToString();
await s3Client.PutObjectAsync(new PutObjectRequest
{
BucketName = bucket,
Key = key,
InputStream = new MemoryStream(Encoding.UTF8.GetBytes(content)),
AutoCloseStream = true
}, cancellationToken);
// generate invalid key which should result KeyTooLongError
var invalidObjectKey = string.Join(string.Empty, Enumerable.Repeat("a", 1025));
// delete objects
var deleteObjectsRequest = new DeleteObjectsRequest { BucketName = bucket };
deleteObjectsRequest.AddKey(key);
deleteObjectsRequest.AddKey(invalidObjectKey);
try
{
await s3Client.DeleteObjectsAsync(deleteObjectsRequest, cancellationToken);
}
catch (DeleteObjectsException e)
{
Console.WriteLine("This is expected! {0}", e);
}
catch (AmazonS3Exception e)
{
Console.WriteLine("This is not expected! {0}", e);
}
// the valid file should be deleted
var response = await s3Client.ListObjectsAsync(bucket, key, cancellationToken);
Console.WriteLine(response.S3Objects.Any() ? "Object found. This is not expected" : "Object deleted. This is expected");
Possible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
AWSSDK.S3 4.0.0.5
AWSSDK.S3 3.7.416.29
Targeted .NET Platform
.NET 8
Operating System and version
Ubuntu