Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented atomic_if_autocommit.

It disables transaction management entirely when AUTOCOMMIT is False.
  • Loading branch information...
commit f7245b83bb2df9d66a375d46a4be8de093957fa7 1 parent 09ba70f
@aaugustin aaugustin authored
Showing with 22 additions and 4 deletions.
  1. +22 −4 django/db/transaction.py
View
26 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
Please sign in to comment.
Something went wrong with that request. Please try again.