googleapis / python-firestore

Apache License 2.0
219 stars 75 forks source link

Commit time and write results aren't set after the transaction is committed via decorated transactional function #927

Closed rostyq closed 1 month ago

rostyq commented 4 months ago

Currently, it is not possible to check transformation results after a successful transaction run in a decorated function without additional read access to firestore database.

Environment details

Steps to reproduce

  1. Implement a @transactional (or @async_transactional) function using any firestore transforms (for example SERVER_TIMESTAMP)
  2. Run a successful Transaction (or AsyncTransaction) in the decorated function
  3. Access commit_time and write_results

Code example

from google.cloud.firestore_v1.client import Client
from google.cloud.firestore_v1.transaction import Transaction, transactional
from google.cloud.firestore_v1.transforms import SERVER_TIMESTAMP

client = Client()

@transactional
def run(t: Transaction):
    t.set(client.document("examples/example"), {"server_timestamp": SERVER_TIMESTAMP})

t = client.transaction()

run(t)

print(t.commit_time)
print(t.write_results)
daniel-sanche commented 1 month ago

I just looked at this, and it seems like commit_time and write_results are inherited from BaseBatch, but not used by the Transaction subclass

It looks like we just need to add these lines from Batch into Transaction._commit. I think it would make sense to make the change