Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed firestore _utils.py #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions firebase/firestore/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def _decode_datastore(value):
elif value.get('booleanValue') is not None:
return bool(value['booleanValue'])

elif value.get('bytesValue'):
elif value.get('bytesValue') is not None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide me an example, where this fails if is not None is note used here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple.

If value.get() returns integer 0 or float 0.0 then you will miss casting to int or float and returning proper value. Unfortunately values equal to zero are treated equal to False. But in this case this is a problem because we can store zero value inside Firestore and zero is also valid integer number. So it's better to check always with None and treat every not None value as valid.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you didn't understand my question. For integer and double, your logic is correct. But does the same apply for bytes? My question was specific to bytes, thus that's the line where I commented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks!

True, probably for bytes it's not needed.

return b64decode(value['bytesValue'].encode('utf-8'))

elif value.get('integerValue'):
elif value.get('integerValue') is not None:
return int(value['integerValue'])

elif value.get('doubleValue'):
elif value.get('doubleValue') is not None:
return float(value['doubleValue'])

elif isinstance(value.get('stringValue'), str):
Expand Down