Skip to content

Firestore: Can't get data in transaction.get call #8

@mpkasp

Description

@mpkasp

Environment details

  1. Specify the API at the beginning of the title: Firestore
  2. OS type and version: MacOS 10.15.2
  3. Python version and virtual environment information: python --version: Python 3.7.4
  4. google-cloud- version: pip show google-<service> or pip freeze: google-cloud-firestore==1.6.1

Steps to reproduce

  1. Create a document in your firestore database.
  2. Run the code below, which will raise an AttributeError: 'bytes' object has no attribute 'in_progress'.

Code example

transaction = db.transaction()
doc_ref = ... # get a reference to the document you created in step 1 above

@firestore.transactional
def update_in_transaction(transaction, doc_ref):
    docs = transaction.get(doc_ref)
    for doc in docs:
        print(doc)

Stack trace

# Abbreviated stack trace
  File ".../venv/lib/python3.7/site-packages/google/cloud/firestore_v1/client.py", line 440, in get_all
    transaction=_helpers.get_transaction_id(transaction),
  File ".../venv/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 934, in get_transaction_id
    if not transaction.in_progress:
AttributeError: 'bytes' object has no attribute 'in_progress'

Additional Notes

It appears the helper function get_transaction_id is expecting a Transaction object, but both the Transaction.get() and Transaction.get_all() calls are passing a Transaction._id.

When I changed line 230 of transaction.py from:
return ref_or_query.stream(transaction=self._id)
to:
return ref_or_query.stream(transaction=self)

It appears to fix the issue.

Metadata

Metadata

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