Skip to content

Firestore: Collection.on_snapshot does not work correctly on nested collections #7515

@Kyras

Description

@Kyras

EDIT: Problem Found, see my next comment !

Collection.on_snapshot works only on top-level collections.
Calling on_snapshot on any sub-collection does nothing. It will be called once, where
first two arguments will be empty arrays, and last one will be correct timestamp, no matter what is actually inside of the collection. It will never be called again.

Someone already found this issue on the Stack Overflow:
https://stackoverflow.com/questions/54407320/firestore-listen-to-documents-in-a-subcollection

But no response given, nor any similiar issue opened.

Environment details

Fedora 29, Linux 4.20.14.-200.fc29.x86_64
Python 3.6.8 (virtualenv)

google-api-core==1.8.1 google-auth==1.6.3 google-cloud-core==0.29.1 google-cloud-firestore==0.31.0 google-cloud-storage==1.14.0 google-resumable-media==0.3.2 

Steps to reproduce

  1. Create document with subcollection in Firestore
  2. Attach any listener on created collection

Code example

db = firestore.Client() def on_snapshot(snapshot, changes, ts): for doc in snapshot: print(doc) # This would work as expected db.collection("users").on_snapshot(on_snapshot) # These will do nothing db.collection("users/USER/values").on_snapshot(on_snapshot) db.collection("users", "USER", "values").on_snapshot(on_snapshot) db.collection("users").document("USER").collection("values").on_snapshot(on_snapshot)

As pointed out, I am rewriting Node.js and similar code does indeed work in Node, but not in the Python version

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the Firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions