Skip to content

Commit

Permalink
Preserve reference to missing documents in 'Client.get_all'. (#8472)
Browse files Browse the repository at this point in the history
Closes #7564.
  • Loading branch information
pchauhan-qlogic authored and tseaver committed Jun 26, 2019
1 parent 0c1517a commit 83f0262
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion firestore/google/cloud/firestore_v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,9 @@ def _parse_batch_get(get_doc_response, reference_map, client):
update_time=get_doc_response.found.update_time,
)
elif result_type == "missing":
reference = _get_reference(get_doc_response.missing, reference_map)
snapshot = DocumentSnapshot(
None,
reference,
None,
exists=False,
read_time=get_doc_response.read_time,
Expand Down
1 change: 1 addition & 0 deletions firestore/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ def test_get_all(client, cleanup):
assert snapshots[0].exists
assert snapshots[1].exists
assert not snapshots[2].exists

snapshots = [snapshot for snapshot in snapshots if snapshot.exists]
id_attr = operator.attrgetter("id")
snapshots.sort(key=id_attr)
Expand Down
9 changes: 7 additions & 2 deletions firestore/tests/unit/v1/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,16 @@ def test_found(self):
self.assertEqual(snapshot.update_time, update_time)

def test_missing(self):
from google.cloud.firestore_v1.document import DocumentReference

ref_string = self._dummy_ref_string()
response_pb = _make_batch_response(missing=ref_string)

snapshot = self._call_fut(response_pb, {})
document = DocumentReference("fizz", "bazz", client=mock.sentinel.client)
reference_map = {ref_string: document}
snapshot = self._call_fut(response_pb, reference_map)
self.assertFalse(snapshot.exists)
self.assertEqual(snapshot.id, "bazz")
self.assertIsNone(snapshot._data)

def test_unset_result_type(self):
response_pb = _make_batch_response()
Expand Down

0 comments on commit 83f0262

Please sign in to comment.