From 9f2ad5cabffe86b1e575261d0248767084229c5e Mon Sep 17 00:00:00 2001 From: HemangChothani Date: Mon, 16 Mar 2020 17:54:47 +0530 Subject: [PATCH 1/4] doc(firestore): change on_snapshot document --- google/cloud/firestore_v1/collection.py | 5 +++-- google/cloud/firestore_v1/document.py | 7 ++++--- google/cloud/firestore_v1/query.py | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/google/cloud/firestore_v1/collection.py b/google/cloud/firestore_v1/collection.py index 27c3eeaa3..11a2d9fe4 100644 --- a/google/cloud/firestore_v1/collection.py +++ b/google/cloud/firestore_v1/collection.py @@ -420,7 +420,8 @@ def on_snapshot(self, callback): provided callback is run on the snapshot of the documents. Args: - callback (Callable[[:class:`~google.cloud.firestore.collection.CollectionSnapshot`], NoneType]): + callback (Callable[List[:class:`~google.cloud.firestore_v1.collection.CollectionSnapshot`], \ + List[:class:`~google.cloud.firestore_v1.watch.DocumentChange`], datetime.datetime], NoneType): a callback to run when a change occurs. Example: @@ -430,7 +431,7 @@ def on_snapshot(self, callback): collection_ref = db.collection(u'users') def on_snapshot(collection_snapshot, changes, read_time): - for doc in collection_snapshot.documents: + for doc in collection_snapshot: print(u'{} => {}'.format(doc.id, doc.to_dict())) # Watch this collection diff --git a/google/cloud/firestore_v1/document.py b/google/cloud/firestore_v1/document.py index 571315e87..6e937c51d 100644 --- a/google/cloud/firestore_v1/document.py +++ b/google/cloud/firestore_v1/document.py @@ -500,7 +500,8 @@ def on_snapshot(self, callback): provided callback is run on the snapshot. Args: - callback(Callable[[:class:`~google.cloud.firestore.document.DocumentSnapshot`], NoneType]): + callback(Callable[List[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`], \ + List[:class:`~google.cloud.firestore_v1.watch.DocumentChange`], datetime.datetime], NoneType): a callback to run when a change occurs Example: @@ -513,8 +514,8 @@ def on_snapshot(self, callback): collection_ref = db.collection(u'users') def on_snapshot(document_snapshot, changes, read_time): - doc = document_snapshot - print(u'{} => {}'.format(doc.id, doc.to_dict())) + for doc in collection_snapshot.documents: + print(u'{} => {}'.format(doc.id, doc.to_dict())) doc_ref = db.collection(u'users').document( u'alovelace' + unique_resource_id()) diff --git a/google/cloud/firestore_v1/query.py b/google/cloud/firestore_v1/query.py index 6a6326c90..05980682f 100644 --- a/google/cloud/firestore_v1/query.py +++ b/google/cloud/firestore_v1/query.py @@ -791,7 +791,8 @@ def on_snapshot(self, callback): provided callback is run on the snapshot of the documents. Args: - callback(Callable[[:class:`~google.cloud.firestore.query.QuerySnapshot`], NoneType]): + callback(Callable[List[:class:`~google.cloud.firestore_v1.query.QuerySnapshot`], \ + List[:class:`~google.cloud.firestore_v1.watch.DocumentChange`], datetime.datetime], NoneType): a callback to run when a change occurs. Example: From ab71c7e0a704dbcbf46de136fb4f89945dfe8c91 Mon Sep 17 00:00:00 2001 From: HemangChothani Date: Mon, 16 Mar 2020 18:21:41 +0530 Subject: [PATCH 2/4] doc(firestore): nit --- google/cloud/firestore_v1/collection.py | 2 +- google/cloud/firestore_v1/document.py | 4 ++-- google/cloud/firestore_v1/query.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google/cloud/firestore_v1/collection.py b/google/cloud/firestore_v1/collection.py index 11a2d9fe4..5c3e468fa 100644 --- a/google/cloud/firestore_v1/collection.py +++ b/google/cloud/firestore_v1/collection.py @@ -431,7 +431,7 @@ def on_snapshot(self, callback): collection_ref = db.collection(u'users') def on_snapshot(collection_snapshot, changes, read_time): - for doc in collection_snapshot: + for doc in collection_snapshot.document: print(u'{} => {}'.format(doc.id, doc.to_dict())) # Watch this collection diff --git a/google/cloud/firestore_v1/document.py b/google/cloud/firestore_v1/document.py index 6e937c51d..786deee95 100644 --- a/google/cloud/firestore_v1/document.py +++ b/google/cloud/firestore_v1/document.py @@ -500,7 +500,7 @@ def on_snapshot(self, callback): provided callback is run on the snapshot. Args: - callback(Callable[List[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`], \ + callback (Callable[List[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`], \ List[:class:`~google.cloud.firestore_v1.watch.DocumentChange`], datetime.datetime], NoneType): a callback to run when a change occurs @@ -514,7 +514,7 @@ def on_snapshot(self, callback): collection_ref = db.collection(u'users') def on_snapshot(document_snapshot, changes, read_time): - for doc in collection_snapshot.documents: + for doc in document_snapshot: print(u'{} => {}'.format(doc.id, doc.to_dict())) doc_ref = db.collection(u'users').document( diff --git a/google/cloud/firestore_v1/query.py b/google/cloud/firestore_v1/query.py index 05980682f..bf2cab980 100644 --- a/google/cloud/firestore_v1/query.py +++ b/google/cloud/firestore_v1/query.py @@ -791,7 +791,7 @@ def on_snapshot(self, callback): provided callback is run on the snapshot of the documents. Args: - callback(Callable[List[:class:`~google.cloud.firestore_v1.query.QuerySnapshot`], \ + callback (Callable[List[:class:`~google.cloud.firestore_v1.query.QuerySnapshot`], \ List[:class:`~google.cloud.firestore_v1.watch.DocumentChange`], datetime.datetime], NoneType): a callback to run when a change occurs. From 3e1610fe83abf90a2f11af08d69ddaf222cb3c65 Mon Sep 17 00:00:00 2001 From: HemangChothani Date: Mon, 16 Mar 2020 18:51:35 +0530 Subject: [PATCH 3/4] doc(firestore): change in example as not working --- google/cloud/firestore_v1/collection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google/cloud/firestore_v1/collection.py b/google/cloud/firestore_v1/collection.py index 5c3e468fa..88b96e79b 100644 --- a/google/cloud/firestore_v1/collection.py +++ b/google/cloud/firestore_v1/collection.py @@ -430,8 +430,8 @@ def on_snapshot(self, callback): db = firestore_v1.Client() collection_ref = db.collection(u'users') - def on_snapshot(collection_snapshot, changes, read_time): - for doc in collection_snapshot.document: + def on_snapshot(docs, changes, read_time): + for doc in docs: print(u'{} => {}'.format(doc.id, doc.to_dict())) # Watch this collection From ea9fe4ff3764ac99fc83bf4b5ee2aa79830af433 Mon Sep 17 00:00:00 2001 From: HemangChothani Date: Tue, 17 Mar 2020 10:31:37 +0530 Subject: [PATCH 4/4] doc(firestore): change in document snapshot example --- google/cloud/firestore_v1/document.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google/cloud/firestore_v1/document.py b/google/cloud/firestore_v1/document.py index 786deee95..b431e26da 100644 --- a/google/cloud/firestore_v1/document.py +++ b/google/cloud/firestore_v1/document.py @@ -513,8 +513,8 @@ def on_snapshot(self, callback): db = firestore_v1.Client() collection_ref = db.collection(u'users') - def on_snapshot(document_snapshot, changes, read_time): - for doc in document_snapshot: + def on_snapshot(docs, changes, read_time): + for doc in docs: print(u'{} => {}'.format(doc.id, doc.to_dict())) doc_ref = db.collection(u'users').document(