File tree 2 files changed +14
-2
lines changed
src/cloudformation_cli_python_lib
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,12 @@ class RequestData:
60
60
previousStackTags : Optional [Mapping [str , Any ]] = None
61
61
previousSystemTags : Optional [Mapping [str , Any ]] = None
62
62
63
+ def __init__ (self , ** kwargs : Any ) -> None :
64
+ dataclass_fields = {f .name for f in fields (self )}
65
+ for k , v in kwargs .items ():
66
+ if k in dataclass_fields :
67
+ setattr (self , k , v )
68
+
63
69
@classmethod
64
70
def deserialize (cls , json_data : MutableMapping [str , Any ]) -> "RequestData" :
65
71
req_data = RequestData (** json_data )
Original file line number Diff line number Diff line change @@ -78,18 +78,24 @@ def test_handler_request_serde_roundtrip():
78
78
"previousResourceProperties" : None ,
79
79
"stackTags" : {"tag1" : "abc" },
80
80
"previousStackTags" : {"tag1" : "def" },
81
+ "undesiredField" : "value" ,
81
82
},
82
83
"stackId" : "arn:aws:cloudformation:us-east-1:123456789012:stack/SampleStack/e72"
83
84
"2ae60-fe62-11e8-9a0e-0ae8cc519968" ,
84
85
}
86
+ undesired = "undesiredField"
85
87
ser = HandlerRequest .deserialize (payload ).serialize ()
86
88
# remove None values from payload
87
89
expected = {
88
- k : {k : v for k , v in payload ["requestData" ].items () if v is not None }
90
+ k : {
91
+ k : v
92
+ for k , v in payload ["requestData" ].items ()
93
+ if v is not None and k not in undesired
94
+ }
89
95
if k == "requestData"
90
96
else v
91
97
for k , v in payload .items ()
92
- if v is not None
98
+ if v is not None and k not in undesired
93
99
}
94
100
95
101
assert ser == expected
You can’t perform that action at this time.
0 commit comments