File tree 3 files changed +21
-1
lines changed
aws_lambda_powertools/utilities/data_classes
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -182,8 +182,10 @@ def approximate_creation_date_time(self) -> Optional[int]:
182
182
item = self .get ("ApproximateCreationDateTime" )
183
183
return None if item is None else int (item )
184
184
185
+ # This override breaks the Mapping protocol of DictWrapper, it's left here for backwards compatibility with
186
+ # a 'type: ignore' comment. This is currently the only subclass of DictWrapper that breaks this protocol.
185
187
@property
186
- def keys (self ) -> Optional [Dict [str , AttributeValue ]]:
188
+ def keys (self ) -> Optional [Dict [str , AttributeValue ]]: # type: ignore
187
189
"""The primary key attribute(s) for the DynamoDB item that was modified."""
188
190
return _attribute_value_dict (self ._data , "Keys" )
189
191
Original file line number Diff line number Diff line change 74
74
AttributeValueType ,
75
75
DynamoDBRecordEventName ,
76
76
DynamoDBStreamEvent ,
77
+ StreamRecord ,
77
78
StreamViewType ,
78
79
)
79
80
from aws_lambda_powertools .utilities .data_classes .event_source import event_source
@@ -630,6 +631,23 @@ def test_dynamo_attribute_value_type_error():
630
631
print (attribute_value .get_type )
631
632
632
633
634
+ def test_stream_record_keys_with_valid_keys ():
635
+ attribute_value = {"Foo" : "Bar" }
636
+ sr = StreamRecord ({"Keys" : {"Key1" : attribute_value }})
637
+ assert sr .keys == {"Key1" : AttributeValue (attribute_value )}
638
+
639
+
640
+ def test_stream_record_keys_with_no_keys ():
641
+ sr = StreamRecord ({})
642
+ assert sr .keys is None
643
+
644
+
645
+ def test_stream_record_keys_overrides_dict_wrapper_keys ():
646
+ data = {"Keys" : {"key1" : {"attr1" : "value1" }}}
647
+ sr = StreamRecord (data )
648
+ assert sr .keys != data .keys ()
649
+
650
+
633
651
def test_event_bridge_event ():
634
652
event = EventBridgeEvent (load_event ("eventBridgeEvent.json" ))
635
653
You can’t perform that action at this time.
0 commit comments