summaryrefslogtreecommitdiff
path: root/django/db/transaction.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-03-07 11:38:21 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-03-11 14:48:55 +0100
commitf7245b83bb2df9d66a375d46a4be8de093957fa7 (patch)
tree537be4d6cdebc677270ec7fdaa2db5543d7aeda0 /django/db/transaction.py
parent09ba70f9f1844680ac0e0b3a7c38ff7113cbdb02 (diff)
Implemented atomic_if_autocommit.
It disables transaction management entirely when AUTOCOMMIT is False.
Diffstat (limited to 'django/db/transaction.py')
-rw-r--r--django/db/transaction.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/django/db/transaction.py b/django/db/transaction.py
index eb9d85e274..0799d23bb6 100644
--- a/django/db/transaction.py
+++ b/django/db/transaction.py
@@ -308,6 +308,24 @@ def atomic(using=None):
return Atomic(using)
+def atomic_if_autocommit(using=None):
+ # This variant only exists to support the ability to disable transaction
+ # management entirely in the DATABASES setting. It doesn't care about the
+ # autocommit state at run time.
+ db = DEFAULT_DB_ALIAS if callable(using) else using
+ autocommit = get_connection(db).settings_dict['AUTOCOMMIT']
+
+ if autocommit:
+ return atomic(using)
+ else:
+ # Bare decorator: @atomic_if_autocommit
+ if callable(using):
+ return using
+ # Decorator: @atomic_if_autocommit(...)
+ else:
+ return lambda func: func
+
+
############################################
# Deprecated decorators / context managers #
############################################
@@ -431,13 +449,13 @@ def commit_on_success_unless_managed(using=None):
Transitory API to preserve backwards-compatibility while refactoring.
Once the legacy transaction management is fully deprecated, this should
- simply be replaced by atomic. Until then, it's necessary to avoid making a
- commit where Django didn't use to, since entering atomic in managed mode
- triggers a commmit.
+ simply be replaced by atomic_if_autocommit. Until then, it's necessary to
+ avoid making a commit where Django didn't use to, since entering atomic in
+ managed mode triggers a commmit.
"""
connection = get_connection(using)
if connection.autocommit or connection.in_atomic_block:
- return atomic(using)
+ return atomic_if_autocommit(using)
else:
def entering(using):
pass