python-mock-firestore
python-mock-firestore copied to clipboard
DocumentSnapshot.get() should return None instead of throwing a KeyError
The current implementation works pretty well, but it has one flaw. It throws a KeyError when the document itself does not exist, but a subcollection does. According to the actual Firestore implementation it considers the document to be non-existent, even when a subcollection for that path exists.
Example:
users/foo
<no data>
users/foo/items
{
"name": "My Item"
}
then
db.collection("users").document("foo").get().get("name") # should return None, but throws KeyError instead
I briefly glared at the source code and I think it's because it stores both document and subcollection data in the same _doc property.