-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Somebody asks in the Slack:
Question about spanner python APIs, specifically transactions.
In a read-write transaction, is it possible to return the updated
value without hitting the database again?let's say I have the following transaction (pretty much the example from the docs)
second_album_result = transaction.read( table='Albums', columns=('MarketingBudget',), keyset=second_album_keyset, limit=1) second_album_row = list(second_album_result)[0] second_album_budget = second_album_row[0] second_album_budget += 10000000 transaction.update(table=mytable, columns=('MarketingBudget'), keyset=second_album_keyset, values=[(second_album_budget)] ) return second_album_budget database.run_in_transaction(f)is the
returnat all possible?
I believe that this is currently not possible in the Python library, because when you pass a closure to run_in_transaction, the return value always gets ignored, and it just returns the commit timestamp.
However this is possible in the Cloud Spanner Java library, and being be able to return whatever you want from the body of a transactional function in the case that a transaction successfully commits is extremely useful.
yixizhang and volokluev
Metadata
Metadata
Assignees
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.