File tree 3 files changed +12
-12
lines changed
aws_lambda_powertools/utilities/data_classes
3 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -32,14 +32,14 @@ def key(self) -> str:
32
32
return unquote_plus (self ["key" ])
33
33
34
34
@property
35
- def size (self ) -> str :
36
- """Object size"""
37
- return self [ "size" ]
35
+ def size (self ) -> Optional [ int ] :
36
+ """Object size. Object deletion event doesn't contain size. """
37
+ return self . get ( "size" )
38
38
39
39
@property
40
- def etag (self ) -> Optional [ str ] :
41
- """Object etag"""
42
- return self .get ("etag" )
40
+ def etag (self ) -> str :
41
+ """Object etag. Object deletion event doesn't contain etag; we default to empty string """
42
+ return self .get ("etag" , "" )
43
43
44
44
@property
45
45
def version_id (self ) -> str :
@@ -178,8 +178,8 @@ def size(self) -> int:
178
178
179
179
@property
180
180
def etag (self ) -> str :
181
- """object eTag"""
182
- return self ["s3" ]["object" ][ "eTag" ]
181
+ """Object eTag. Object deletion event doesn't contain eTag; we default to empty string """
182
+ return self ["s3" ]["object" ]. get ( "eTag" , "" )
183
183
184
184
@property
185
185
def version_id (self ) -> Optional [str ]:
Original file line number Diff line number Diff line change @@ -26,10 +26,10 @@ def test_s3_eventbridge_notification_detail_parsed(raw_event: Dict):
26
26
assert parsed_event .detail .deletion_type == raw_event ["detail" ].get ("deletion-type" )
27
27
assert parsed_event .detail .destination_access_tier == raw_event ["detail" ].get ("destination-access-tier" )
28
28
assert parsed_event .detail .destination_storage_class == raw_event ["detail" ].get ("destination-storage-class" )
29
- assert parsed_event .detail .object .etag == raw_event ["detail" ]["object" ][ "etag" ]
29
+ assert parsed_event .detail .object .etag == raw_event ["detail" ]["object" ]. get ( "etag" , "" )
30
30
assert parsed_event .detail .object .key == raw_event ["detail" ]["object" ]["key" ]
31
31
assert parsed_event .detail .object .sequencer == raw_event ["detail" ]["object" ]["sequencer" ]
32
- assert parsed_event .detail .object .size == raw_event ["detail" ]["object" ][ "size" ]
32
+ assert parsed_event .detail .object .size == raw_event ["detail" ]["object" ]. get ( "size" )
33
33
assert parsed_event .detail .reason == raw_event ["detail" ].get ("reason" )
34
34
assert parsed_event .detail .version == raw_event ["detail" ].get ("version" )
35
35
assert parsed_event .detail .request_id == raw_event ["detail" ]["request-id" ]
Original file line number Diff line number Diff line change @@ -52,8 +52,8 @@ def test_s3_eventbridge_notification_object_deleted_event():
52
52
assert model .detail .version == raw_event ["detail" ]["version" ]
53
53
assert model .detail .bucket .name == raw_event ["detail" ]["bucket" ]["name" ]
54
54
assert model .detail .object .key == raw_event ["detail" ]["object" ]["key" ]
55
- assert model .detail .object .size == raw_event ["detail" ]["object" ][ "size" ]
56
- assert model .detail .object .etag == raw_event ["detail" ]["object" ][ "etag" ]
55
+ assert model .detail .object .size == raw_event ["detail" ]["object" ]. get ( "size" )
56
+ assert model .detail .object .etag == raw_event ["detail" ]["object" ]. get ( "etag" )
57
57
assert model .detail .object .sequencer == raw_event ["detail" ]["object" ]["sequencer" ]
58
58
assert model .detail .request_id == raw_event ["detail" ]["request-id" ]
59
59
assert model .detail .requester == raw_event ["detail" ]["requester" ]
You can’t perform that action at this time.
0 commit comments