

@utils.positional(1)
def transaction(callback, **ctx_options):
    "Run a callback in a transaction.\n\n  Args:\n    callback: A function or tasklet to be called.\n    **ctx_options: Transaction options.\n\n  Useful options include:\n    retries=N: Retry up to N times (i.e. try up to N+1 times)\n    propagation=<flag>: Determines how an existing transaction should be\n      propagated, where <flag> can be one of the following:\n      TransactionOptions.NESTED: Start a nested transaction (this is the\n        default; but actual nested transactions are not yet implemented,\n        so effectively you can only use this outside an existing transaction).\n      TransactionOptions.MANDATORY: A transaction must already be in progress.\n      TransactionOptions.ALLOWED: If a transaction is in progress, join it.\n      TransactionOptions.INDEPENDENT: Always start a new parallel transaction.\n    xg=True: On the High Replication Datastore, enable cross-group\n      transactions, i.e. allow writing to up to 5 entity groups.\n\n  WARNING: Using anything other than NESTED for the propagation flag\n  can have strange consequences.  When using ALLOWED or MANDATORY, if\n  an exception is raised, the transaction is likely not safe to\n  commit.  When using INDEPENDENT it is not generally safe to return\n  values read to the caller (as they were not read in the caller's\n  transaction).\n\n  Returns:\n    Whatever callback() returns.\n\n  Raises:\n    Whatever callback() raises; datastore_errors.TransactionFailedError\n    if the transaction failed.\n\n  Note:\n    To pass arguments to a callback function, use a lambda, e.g.\n      def my_callback(key, inc):\n        ...\n      transaction(lambda: my_callback(Key(...), 1))\n  "
    fut = transaction_async(callback, **ctx_options)
    return fut.get_result()

dataset/ETHPy150Open GoogleCloudPlatform/datastore-ndb-python/ndb/model.py transaction/original