Skip to content

Commit

Permalink
Fix wrong get_check_exists sample. No exception handling is required …
Browse files Browse the repository at this point in the history
…anymore (#2429)

* Fix wrong get_check_exists sample

There are no more exceptions when no document found in DocumentReference.get() call.

If the document does not exist at the time of the snapshot is taken, the snapshot’s reference, data, update_time, and create_time attributes will all be None and its exists attribute will be False.

https://googleapis.github.io/google-cloud-python/latest/firestore/document.html#google.cloud.firestore_v1.document.DocumentReference.get

Now issues googleapis/google-cloud-python#4530 and googleapis/google-cloud-python#4531 are resolved

* removed unused exceptions import
  • Loading branch information
limexp authored and andrewferlitsch committed Oct 3, 2019
1 parent c438ba1 commit e474a32
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions firestore/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from time import sleep

from google.cloud import firestore
import google.cloud.exceptions


def quickstart_new_instance():
Expand Down Expand Up @@ -217,10 +216,10 @@ def get_check_exists():
# [START get_check_exists]
doc_ref = db.collection(u'cities').document(u'SF')

try:
doc = doc_ref.get()
doc = doc_ref.get()
if doc.exists:
print(u'Document data: {}'.format(doc.to_dict()))
except google.cloud.exceptions.NotFound:
else:
print(u'No such document!')
# [END get_check_exists]

Expand Down

0 comments on commit e474a32

Please sign in to comment.