db.transaction.savepoint()

savepoint(using=None) [source] Creates a new savepoint. This marks a point in the transaction that is known to be in a “good” state. Returns the savepoint ID (sid).

db.transaction.rollback()

rollback(using=None) [source] These functions take a using argument which should be the name of a database. If it isn’t provided, Django uses the "default" database. Django will refuse to commit or to rollback when an atomic() block is active, because that would break atomicity.

db.transaction.on_commit()

on_commit(func, using=None) [source] Pass any function (that takes no arguments) to on_commit(): from django.db import transaction def do_something(): pass # send a mail, invalidate a cache, fire off a Celery task, etc. transaction.on_commit(do_something) You can also wrap your function in a lambda: transaction.on_commit(lambda: some_celery_task.delay('arg1')) The function you pass in will be called immediately after a hypothetical database write made where on_commit() is called wou

db.transaction.non_atomic_requests()

non_atomic_requests(using=None) [source] This decorator will negate the effect of ATOMIC_REQUESTS for a given view: from django.db import transaction @transaction.non_atomic_requests def my_view(request): do_stuff() @transaction.non_atomic_requests(using='other') def my_other_view(request): do_stuff_on_the_other_database() It only works if it’s applied to the view itself.

db.transaction.get_rollback()

get_rollback(using=None) [source]

db.transaction.get_autocommit()

get_autocommit(using=None) [source]

db.transaction.commit()

commit(using=None) [source]

db.transaction.clean_savepoints()

clean_savepoints(using=None) [source] Resets the counter used to generate unique savepoint IDs. The following example demonstrates the use of savepoints: from django.db import transaction # open a transaction @transaction.atomic def viewfunc(request): a.save() # transaction now contains a.save() sid = transaction.savepoint() b.save() # transaction now contains a.save() and b.save() if want_to_keep_b: transaction.savepoint_commit(sid) # open transa

db.transaction.atomic()

atomic(using=None, savepoint=True) [source] Atomicity is the defining property of database transactions. atomic allows us to create a block of code within which the atomicity on the database is guaranteed. If the block of code is successfully completed, the changes are committed to the database. If there is an exception, the changes are rolled back. atomic blocks can be nested. In this case, when an inner block completes successfully, its effects can still be rolled back if an exception is r

db.models.Variance.sample

sample By default, Variance returns the population variance. However, if sample=True, the return value will be the sample variance. SQLite SQLite doesn’t provide Variance out of the box. An implementation is available as an extension module for SQLite. Consult the SQlite documentation for instructions on obtaining and installing this extension.