Skip to content

Commit 900017e

Browse files
committed
Avoid unexpected falsy values and fix geopoint parsing
1 parent 8decc9d commit 900017e

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

firebase/firestore/_utils.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,33 @@ def _decode_datastore(value):
7070
:raises TypeError: For value types that are unsupported.
7171
"""
7272

73-
if value.get('nullValue', False) is None:
73+
if 'nullValue' in value:
7474
return value['nullValue']
7575

76-
elif value.get('booleanValue') is not None:
76+
elif 'booleanValue' in value:
7777
return bool(value['booleanValue'])
7878

79-
elif value.get('bytesValue'):
79+
elif 'bytesValue' in value:
8080
return b64decode(value['bytesValue'].encode('utf-8'))
8181

82-
elif value.get('integerValue'):
82+
elif 'integerValue' in value:
8383
return int(value['integerValue'])
8484

85-
elif value.get('doubleValue'):
85+
elif 'doubleValue' in value:
8686
return float(value['doubleValue'])
8787

88-
elif isinstance(value.get('stringValue'), str):
89-
return str(value['stringValue'])
88+
elif 'stringValue' in value and isinstance(value['stringValue'], str):
89+
return value['stringValue']
9090

91-
elif value.get('mapValue'):
91+
elif 'mapValue' in value:
9292
return _from_datastore(value['mapValue'])
9393

94-
elif value.get('timestampValue'):
94+
elif 'timestampValue' in value:
9595
return DatetimeWithNanoseconds.from_rfc3339(value['timestampValue'])
9696

97-
elif value.get('geoPointValue'):
98-
return GeoPoint(float(value['timestampValue']['latitude']), float(value['timestampValue']['longitude']))
97+
elif 'geoPointValue' in value:
98+
geo = value['geoPointValue']
99+
return GeoPoint(float(geo['latitude']), float(geo['longitude']))
99100

100101
else:
101102
raise TypeError("Cannot convert to a Python Value", value, "Invalid type", type(value))

0 commit comments

Comments
 (0)