Useful options include:
retries=N: Retry up to N times (i.e. try up to N+1 times)
propagation=: Determines how an existing transaction should be
propagated, where can be one of the following:
TransactionOptions.NESTED: Start a nested transaction (this is the
default; but actual nested transactions are not yet implemented,
so effectively you can only use this outside an existing transaction).
TransactionOptions.MANDATORY: A transaction must already be in progress.
TransactionOptions.ALLOWED: If a transaction is in progress, join it.
TransactionOptions.INDEPENDENT: Always start a new parallel transaction.
xg=True: On the High Replication Datastore, enable cross-group
transactions, i.e. allow writing to up to 5 entity groups.
read_only=True: Indicates a transaction will not do any writes, which
potentially allows for more throughput.
WARNING: Using anything other than NESTED for the propagation flag
can have strange consequences. When using ALLOWED or MANDATORY, if
an exception is raised, the transaction is likely not safe to
commit. When using INDEPENDENT it is not generally safe to return
values read to the caller (as they were not read in the caller's
transaction).
Returns
Whatever callback() returns.
Raises
Whatever callback() raises; datastore_errors.TransactionFailedError
if the transaction failed.
Note:
To pass arguments to a callback function, use a lambda, e.g.
def my_callback(key, inc):
...
transaction(lambda: my_callback(Key(...), 1))
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-09-30 UTC."],[[["The `transaction` function executes a provided callback function or tasklet within a transaction context."],["It accepts transaction options, including the number of retries (`retries=N`) and the propagation flag."],["Using propagation flags other than `NESTED` may lead to unpredictable or unsafe transaction behavior."],["The function returns the same value that the callback function returns upon its execution."],["If the transaction fails or if the callback function encounters any error, the callback function will raise the relevant error or `datastore_errors.TransactionFailedError`."]]],[]]