Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed transaction handling in two management commands.

Previously, when createcachetable and flush operated on non-default
databases, they weren't atomic.
  • Loading branch information...
commit 753a22a6352638b7df55176584795ac8c5d4232c 1 parent 0f95608
Aymeric Augustin aaugustin authored
2  django/core/management/commands/createcachetable.py
View
@@ -71,7 +71,7 @@ def create_table(self, database, tablename):
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.atomic():
+ with transaction.atomic(using=database):
with connection.cursor() as curs:
try:
curs.execute("\n".join(full_statement))
2  django/core/management/commands/flush.py
View
@@ -63,7 +63,7 @@ def handle_noargs(self, **options):
if confirm == 'yes':
try:
- with transaction.atomic():
+ with transaction.atomic(using=db):
with connection.cursor() as cursor:
for sql in sql_list:
cursor.execute(sql)
8 tests/cache/tests.py
View
@@ -981,9 +981,11 @@ def test_createcachetable_observes_database_router(self):
# 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)
Please sign in to comment.
Something went wrong with that request. Please try again.