module documentation

Undocumented

Class ​Transaction​Management​Error Transaction management is used improperly.
Function atomic Undocumented
Function clean​_savepoints Reset the counter used to generate unique savepoint ids in this thread.
Function commit Commit a transaction.
Function get​_autocommit Get the autocommit status of the connection.
Function get​_rollback Get the "needs rollback" flag -- for advanced use only.
Function non​_atomic​_requests Undocumented
Function on​_commit Register func to be called when the current transaction is committed. If the current transaction is rolled back, func will not be called.
Function rollback Roll back a transaction.
Function savepoint Create a savepoint (if supported and required by the backend) inside the current transaction. Return an identifier for the savepoint that will be used for the subsequent rollback or commit.
Function savepoint​_commit Commit the most recent savepoint (if one exists). Do nothing if savepoints are not supported.
Function savepoint​_rollback Roll back the most recent savepoint (if one exists). Do nothing if savepoints are not supported.
Function set​_autocommit Set the autocommit status of the connection.
Function set​_rollback Set or unset the "needs rollback" flag -- for advanced use only.
Class ​Atomic Guarantee the atomic execution of a given block.
Function ​_non​_atomic​_requests Undocumented
Function get​_connection Get a database connection by name, or the default database connection if no name is provided. This is a private API.
Function mark​_for​_rollback​_on​_error No summary
def atomic(using=None, savepoint=True, durable=False):

Undocumented

def clean_savepoints(using=None):
Reset the counter used to generate unique savepoint ids in this thread.
def commit(using=None):
Commit a transaction.
def get_autocommit(using=None):
Get the autocommit status of the connection.
def get_rollback(using=None):
Get the "needs rollback" flag -- for advanced use only.
def non_atomic_requests(using=None):

Undocumented

def on_commit(func, using=None):
Register func to be called when the current transaction is committed. If the current transaction is rolled back, func will not be called.
def rollback(using=None):
Roll back a transaction.
def savepoint(using=None):
Create a savepoint (if supported and required by the backend) inside the current transaction. Return an identifier for the savepoint that will be used for the subsequent rollback or commit.
def savepoint_commit(sid, using=None):
Commit the most recent savepoint (if one exists). Do nothing if savepoints are not supported.
def savepoint_rollback(sid, using=None):
Roll back the most recent savepoint (if one exists). Do nothing if savepoints are not supported.
def set_autocommit(autocommit, using=None):
Set the autocommit status of the connection.
def set_rollback(rollback, using=None):

Set or unset the "needs rollback" flag -- for advanced use only.

When rollback is True, trigger a rollback when exiting the innermost enclosing atomic block that has savepoint=True (that's the default). Use this to force a rollback without raising an exception.

When rollback is False, prevent such a rollback. Use this only after rolling back to a known-good state! Otherwise, you break the atomic block and data corruption may occur.

def _non_atomic_requests(view, using):

Undocumented

def get_connection(using=None):
Get a database connection by name, or the default database connection if no name is provided. This is a private API.
@contextmanager
def mark_for_rollback_on_error(using=None):

Internal low-level utility to mark a transaction as "needs rollback" when an exception is raised while not enforcing the enclosed block to be in a transaction. This is needed by Model.save() and friends to avoid starting a transaction when in autocommit mode and a single query is executed.

It's equivalent to:

connection = get_connection(using) if connection.get_autocommit():

yield
else:
with transaction.atomic(using=using, savepoint=False):
yield

but it uses low-level utilities to avoid performance overhead.