Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Arushi201296 opened this issue Jul 13, 2021 · 2 comments · Fixed by #467
Closed

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

Arushi201296 opened this issue Jul 13, 2021 · 2 comments · Fixed by #467
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@Arushi201296
Copy link

Arushi201296 commented Jul 13, 2021

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)
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Jul 13, 2021
@tseaver tseaver added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jul 13, 2021
@tseaver tseaver self-assigned this Jul 13, 2021
@tseaver
Copy link
Contributor

tseaver commented Jul 13, 2021

@Arushi201296 Thanks for the report!

tseaver added a commit that referenced this issue Oct 4, 2021
tseaver added a commit that referenced this issue Oct 8, 2021
Document that 'DocumentSnapshot.create_time' and
'DocumentSnapshot.update_time' are instances of
'proto.datetime_helpers.DatetimeWithNanoseconds'.

Closes #398.
Closes #391.
@tseaver
Copy link
Contributor

tseaver commented Oct 8, 2021

@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
Labels
api: firestore Issues related to the googleapis/python-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
2 participants