View source on GitHub |
Run a callback in a transaction.
google.appengine.ext.ndb.transaction(
callback, **ctx_options
)
Args | |
---|---|
callback
|
A function or tasklet to be called. |
**ctx_options
|
Transaction options. |
Useful options include:
retries=N: Retry up to N times (i.e. try up to N+1 times)
propagation=
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))