Skip to content

Commit

Permalink
s3_bucket: fix VersionId==null when s3 object not versioned (#1538)
Browse files Browse the repository at this point in the history
s3_bucket: fix VersionId==null when s3 object not versioned

SUMMARY

Boto3 1.26.129 (possibly earlier) returns "VersionId": "null" from s3_client.list_object_versions() when s3 objects are not versioned.  Previously, "VersionId" was None when an s3 object was not versioned.  This change broke s3_bucket.destroy_bucket() because the the VersionId was no longer popped (line 1166) when the s3 object was not versioned, and the subsequent attempts to delete the s3 object failed as the "VersionId" was absolutely not "null".  Adding in `or fk.get("VersionId")=="null" will catch this new value for non-versioned s3 objects while allowing backwards compatibility with previous versions that return None for "VersionId".

Fixes #1533 s3_bucket.destroy_bucket fails to delete unversioned items
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

s3_bucket.py
ADDITIONAL INFORMATION

Ensure that there is an s3 bucket with objects in it

name: Remove buckets
s3_bucket:
name: "my_bucket_with_objects_with_no_versioning"
state: absent
force: yes

Reviewed-by: Mark Chappell
(cherry picked from commit 94bb14c)
  • Loading branch information
evohnave authored and patchback[bot] committed May 11, 2023
1 parent 3a769a8 commit dfea08e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/1538-s3-null.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- s3_bucket - fixes issue when deleting a bucket with unversioned objects (https://github.com/ansible-collections/amazon.aws/issues/1533).
2 changes: 1 addition & 1 deletion plugins/modules/s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ def destroy_bucket(s3_client, module):
# unversioned objects are deleted using `DeleteObject`
# rather than `DeleteObjectVersion`, improving backwards
# compatibility with older IAM policies.
if not fk.get("VersionId"):
if not fk.get("VersionId") or fk.get("VersionId") == "null":
fk.pop("VersionId")

if formatted_keys:
Expand Down

0 comments on commit dfea08e

Please sign in to comment.