Skip to content

Firestore: Clarify documentation for '{Document,Collection}.on_snapshot'. #9250

@billyrrr

Description

@billyrrr

on_snapshot defined in DocumentReference documentation is inconsistent with those of Watch and Product Documentation.

In DocumentReference documentation, we have

callback(Callable[[:class:`~google.cloud.firestore.document.DocumentSnapshot`], NoneType]):
a callback to run when a change occurs

and

def on_snapshot(document_snapshot):
doc = document_snapshot
print(u'{} => {}'.format(doc.id, doc.to_dict()))

In Watch documentation, we have

snapshot_callback: Callback method to process snapshots.
Args:
docs (List(DocumentSnapshot)): A callback that returns the
ordered list of documents stored in this snapshot.
changes (List(str)): A callback that returns the list of
changed documents since the last snapshot delivered for
this watch.
read_time (string): The ISO 8601 time at which this
snapshot was obtained.

In Product Documentation, we have

# Create a callback on_snapshot function to capture changes
def on_snapshot(doc_snapshot, changes, read_time):
    for doc in doc_snapshot:
        print(u'Received document snapshot: {}'.format(doc.id))

doc_ref = db.collection(u'cities').document(u'SF')

# Watch the document
doc_watch = doc_ref.on_snapshot(on_snapshot)

The function signature in DocumentReference takes 1 argument, but the function signature in Watch and Product Documentation takes 3 arguments. Are these referring to the same function? If so, the documentation in DocumentReference may be updated to reflect these changes. If not, on_snapshot in Product Documentation may be renamed to a different name than on_snapshot in DocumentReference to be more clear.

Will probably submit a pull request to update documentation in DocumentReference to be consistent with that in Watch.

Thanks!

Metadata

Metadata

Labels

api: firestoreIssues related to the Firestore API.type: docsImprovement to the documentation for an API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions