Skip to content

Commit 2d725cf

Browse files
committed
Fix None while following JSON path of flattening
1 parent bfa8189 commit 2d725cf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

msrest/serialization.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,13 +1101,18 @@ def rest_key_extractor(attr, attr_desc, data):
11011101
key = attr_desc['key']
11021102
working_data = data
11031103

1104-
while '.' in key and working_data:
1104+
while '.' in key:
11051105
dict_keys = _FLATTEN.split(key)
11061106
if len(dict_keys) == 1:
11071107
key = _decode_attribute_map_key(dict_keys[0])
11081108
break
11091109
working_key = _decode_attribute_map_key(dict_keys[0])
11101110
working_data = working_data.get(working_key, data)
1111+
if working_data is None:
1112+
# If at any point while following flatten JSON path see None, it means
1113+
# that all properties under are None as well
1114+
# https://github.com/Azure/msrest-for-python/issues/197
1115+
return None
11111116
key = '.'.join(dict_keys[1:])
11121117

11131118
return working_data.get(key)
@@ -1116,13 +1121,18 @@ def rest_key_case_insensitive_extractor(attr, attr_desc, data):
11161121
key = attr_desc['key']
11171122
working_data = data
11181123

1119-
while '.' in key and working_data:
1124+
while '.' in key:
11201125
dict_keys = _FLATTEN.split(key)
11211126
if len(dict_keys) == 1:
11221127
key = _decode_attribute_map_key(dict_keys[0])
11231128
break
11241129
working_key = _decode_attribute_map_key(dict_keys[0])
11251130
working_data = attribute_key_case_insensitive_extractor(working_key, None, working_data)
1131+
if working_data is None:
1132+
# If at any point while following flatten JSON path see None, it means
1133+
# that all properties under are None as well
1134+
# https://github.com/Azure/msrest-for-python/issues/197
1135+
return None
11261136
key = '.'.join(dict_keys[1:])
11271137

11281138
if working_data:

0 commit comments

Comments
 (0)