diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 29a0c632..d602a567 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -943,13 +943,10 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): key_name = object_["Key"] version_id = object_.get("VersionId", None) - success, _ = self.backend.delete_object( + self.backend.delete_object( bucket_name, undo_clean_key_name(key_name), version_id=version_id ) - if success: - deleted_objects.append((key_name, version_id)) - else: - error_names.append(key_name) + deleted_objects.append((key_name, version_id)) return ( 200, diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 7a9f2d99..7391ffae 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -689,8 +689,7 @@ def test_delete_keys_invalid(): # non-existing key case result = bucket.delete_keys(["abc", "file3"]) - result.deleted.should.have.length_of(1) - result.errors.should.have.length_of(1) + result.deleted.should.have.length_of(2) keys = bucket.get_all_keys() keys.should.have.length_of(3) keys[0].name.should.equal("file1") @@ -4215,6 +4214,22 @@ def test_delete_objects_with_url_encoded_key(key): assert_deleted() +@mock_s3 +def test_delete_objects_unknown_key(): + bucket_name = "test-moto-issue-1581" + client = boto3.client("s3", region_name=DEFAULT_REGION_NAME) + client.create_bucket(Bucket=bucket_name) + client.put_object(Bucket=bucket_name, Key="file1", Body="body") + + s = client.delete_objects( + Bucket=bucket_name, Delete={"Objects": [{"Key": "file1"}, {"Key": "file2"}]} + ) + s["Deleted"].should.have.length_of(2) + s["Deleted"].should.contain({"Key": "file1"}) + s["Deleted"].should.contain({"Key": "file2"}) + client.delete_bucket(Bucket=bucket_name) + + @mock_s3 @mock_config def test_public_access_block(): diff --git a/tests/test_s3bucket_path/test_s3bucket_path.py b/tests/test_s3bucket_path/test_s3bucket_path.py index a1bdc5b0..06ec9caf 100644 --- a/tests/test_s3bucket_path/test_s3bucket_path.py +++ b/tests/test_s3bucket_path/test_s3bucket_path.py @@ -315,8 +315,8 @@ def test_delete_keys_with_invalid(): result = bucket.delete_keys(["abc", "file3"]) - result.deleted.should.have.length_of(1) - result.errors.should.have.length_of(1) + result.deleted.should.have.length_of(2) + result.errors.should.have.length_of(0) keys = bucket.get_all_keys() keys.should.have.length_of(3) keys[0].name.should.equal("file1")