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

Accessing Firestore document in Firebase emulator fails with AttributeError #433

Closed
nksma opened this issue Aug 26, 2021 · 2 comments · Fixed by #434
Closed

Accessing Firestore document in Firebase emulator fails with AttributeError #433

nksma opened this issue Aug 26, 2021 · 2 comments · Fixed by #434
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API.

Comments

@nksma
Copy link

nksma commented Aug 26, 2021

The recent change (4381ad5) assumes _credentials to have id_token attribute, but that's not the case all the time.

https://github.com/googleapis/python-firestore/blame/main/google/cloud/firestore_v1/base_client.py#L183

When it doesn't contain the id_token attribute, AttributeError is raised.
Before checking if id_token is None, we should check if the attribute exists using hasattr()

Environment details

  • OS type and version: Mac OS X (Darwin mac-mini.lan 20.5.0)
  • Python version: 3.8.8
  • pip version: 21.1.2
  • google-cloud-firestore version: 2.3.0

Steps to reproduce

  1. run unit test that reads and writes Firestore document using firebase-emulator:exec

Code example

omitted since it's a straightforward bug.

Stack trace

  File "/opt/venv/lib/python3.8/site-packages/google/cloud/firestore_v1/document.py", line 167, in set
     write_results = batch.commit(**kwargs)
  File "/opt/venv/lib/python3.8/site-packages/google/cloud/firestore_v1/batch.py", line 59, in commit
    commit_response = self._client._firestore_api.commit(
   File "/opt/venv/lib/python3.8/site-packages/google/cloud/firestore_v1/client.py", line 109, in _firestore_api
    return self._firestore_api_helper(
   File "/opt/venv/lib/python3.8/site-packages/google/cloud/firestore_v1/base_client.py", line 152, in _firestore_api_helper
     channel = self._emulator_channel(transport)
   File "/opt/venv/lib/python3.8/site-packages/google/cloud/firestore_v1/base_client.py", line 183, in _emulator_channel
     if self._credentials is not None and self._credentials.id_token is not None:
 AttributeError: 'Credentials' object has no attribute 'id_token'
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Aug 26, 2021
@crwilcox
Copy link
Contributor

What credentials object are you creating? In our testing this wasn't seen, so I wonder if you are creating a non default one? We can harden this, but I am still curious.

@nksma
Copy link
Author

nksma commented Aug 27, 2021

This is how I'm creating the credentials.
cred = firebase_admin.credentials.ApplicationDefault()
firebase_admin.initialize_app(cred)

Hope this helps with improving the test coverage to avoid a similar issue in the future.

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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants