python-mock-firestore icon indicating copy to clipboard operation
python-mock-firestore copied to clipboard

DocumentSnapshot.get() should return None instead of throwing a KeyError

Open hellojappie opened this issue 3 years ago • 0 comments

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.

hellojappie avatar Feb 28 '22 14:02 hellojappie