summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-03-21 18:48:57 +0100
committerTim Graham <timograham@gmail.com>2014-07-24 18:13:12 -0400
commit5ca82ff71baa9d749c98ef68e8f8814cf7afcf5d (patch)
treec19a67168ee39dc494449f1079fcd2f1d3250ea2
parentb918bc921ca104ac0ab877e9fa0f6b49a5242679 (diff)
[1.7.x] Fixed #23089 -- Fixed transaction handling in two management commands.
Previously, when createcachetable and flush operated on non-default databases, they weren't atomic. Backport of 753a22a635 from master
-rw-r--r--django/core/management/commands/createcachetable.py2
-rw-r--r--django/core/management/commands/flush.py2
-rw-r--r--docs/releases/1.6.6.txt4
-rw-r--r--tests/cache/tests.py8
4 files changed, 11 insertions, 5 deletions
diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py
index 909a5d08c8..8a9d0829c5 100644
--- a/django/core/management/commands/createcachetable.py
+++ b/django/core/management/commands/createcachetable.py
@@ -71,7 +71,7 @@ class Command(BaseCommand):
for i, line in enumerate(table_output):
full_statement.append(' %s%s' % (line, ',' if i < len(table_output) - 1 else ''))
full_statement.append(');')
- with transaction.commit_on_success_unless_managed():
+ with transaction.atomic(using=database):
with connection.cursor() as curs:
try:
curs.execute("\n".join(full_statement))
diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py
index 1c21495b35..32c7aa0743 100644
--- a/django/core/management/commands/flush.py
+++ b/django/core/management/commands/flush.py
@@ -62,7 +62,7 @@ Are you sure you want to do this?
if confirm == 'yes':
try:
- with transaction.commit_on_success_unless_managed():
+ with transaction.atomic(using=db):
with connection.cursor() as cursor:
for sql in sql_list:
cursor.execute(sql)
diff --git a/docs/releases/1.6.6.txt b/docs/releases/1.6.6.txt
index c61823bfdc..c8c7a037c0 100644
--- a/docs/releases/1.6.6.txt
+++ b/docs/releases/1.6.6.txt
@@ -22,3 +22,7 @@ Bugfixes
* Restored ``pre_delete`` signals for ``GenericRelation`` cascade deletion
(`#22998 <https://code.djangoproject.com/ticket/22998>`_).
+
+* Fixed transaction handling when specifying non-default database in
+ ``createcachetable`` and ``flush``
+ (`#23089 <https://code.djangoproject.com/ticket/23089>`_).
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 2c541a304d..21a92c3b46 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -989,9 +989,11 @@ class CreateCacheTableForDBCacheTests(TestCase):
# cache table should be created on 'other'
# Queries:
# 1: check table doesn't already exist
- # 2: create the table
- # 3: create the index
- with self.assertNumQueries(3, using='other'):
+ # 2: create savepoint
+ # 3: create the table
+ # 4: create the index
+ # 5: release savepoint
+ with self.assertNumQueries(5, using='other'):
management.call_command('createcachetable',
database='other',
verbosity=0, interactive=False)