Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

DocumentSnapshots cannot be stored in a set, unlike DocumentReference #391

Closed

Description

@Arushi201296

Environment details

  • OS type and version: 64-bit and Ubuntu 18.04.5 LTS
  • Python version: python 3.7
  • pip version: pip 21.1.3
  • google-cloud-firestore version: google-cloud-firestore 2.1.0

Steps to reproduce

  1. Add some documents to Firestore and store the document snapshots in a variable ( say result )
  2. Form a set of the fetched documents set(result)

Code example

from google.cloud import firestore
fs_client = firestore.Client()
result=set()
query = fs_client.collection_group(<collection-group-name>)    
for document_snapshot in query.stream():
        result.add(document_snapshot)

Stack trace

  File "<folder>/venv/lib/python3.7/site-packages/google/cloud/firestore_v1/base_document.py", line 372, in __hash__
    seconds = int(self.update_time.timestamp())
AttributeError: timestamp

The same does not throw an error when we store DocumentReference objects in a set.
Also, modifying __hash__ as below works:

    def __hash__(self):
        seconds = int(self.update_time.seconds)
        nanos = self.update_time.nanos
        return hash(self._reference) + hash(seconds) + hash(nanos)

Activity

  1. added
    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.
    on Jul 13, 2021
  2. self-assigned this
    on Jul 13, 2021
  3. tseaver commented on Jul 13, 2021

    @tseaver
    Contributor

    @Arushi201296 Thanks for the report!

  4. added a commit that references this issue on Oct 4, 2021
    e1e5a97
  5. added a commit that references this issue on Oct 8, 2021
    5e66a73
  6. tseaver commented on Oct 8, 2021

    @tseaver
    Contributor

    @Arushi201296 I ended up adding the necessary testing changes in #467. Thanks again for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/python-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