Skip to content

Commit 9c8cd92

Browse files
authored
Make firestore get_check_exists method work as intended. (#3408)
Since [this commit](googleapis/python-firestore@068089e#diff-6f034fb43c430e2af1248c2da03ec41dR428-R458) firestore's client `get` method is not raising `google.cloud.exceptions.NotFound` if there is no such document. `get_check_exists` function is now working properly - needs to be updated. My proposal is `exists` method (works for me).
1 parent 240190a commit 9c8cd92

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

firestore/cloud-client/snippets.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from time import sleep
1616

1717
from google.cloud import firestore
18-
import google.cloud.exceptions
1918

2019

2120
def quickstart_new_instance():
@@ -217,10 +216,10 @@ def get_check_exists():
217216
# [START get_check_exists]
218217
doc_ref = db.collection(u'cities').document(u'SF')
219218

220-
try:
221-
doc = doc_ref.get()
219+
doc = doc_ref.get()
220+
if doc.exists:
222221
print(u'Document data: {}'.format(doc.to_dict()))
223-
except google.cloud.exceptions.NotFound:
222+
else:
224223
print(u'No such document!')
225224
# [END get_check_exists]
226225

0 commit comments

Comments
 (0)