Fixed transaction handling in two management commands.
Previously, when createcachetable and flush operated on non-default databases, they weren't atomic.
This commit is contained in:
parent
0f9560855e
commit
753a22a635
|
@ -71,7 +71,7 @@ class Command(BaseCommand):
|
||||||
for i, line in enumerate(table_output):
|
for i, line in enumerate(table_output):
|
||||||
full_statement.append(' %s%s' % (line, ',' if i < len(table_output) - 1 else ''))
|
full_statement.append(' %s%s' % (line, ',' if i < len(table_output) - 1 else ''))
|
||||||
full_statement.append(');')
|
full_statement.append(');')
|
||||||
with transaction.atomic():
|
with transaction.atomic(using=database):
|
||||||
with connection.cursor() as curs:
|
with connection.cursor() as curs:
|
||||||
try:
|
try:
|
||||||
curs.execute("\n".join(full_statement))
|
curs.execute("\n".join(full_statement))
|
||||||
|
|
|
@ -63,7 +63,7 @@ Are you sure you want to do this?
|
||||||
|
|
||||||
if confirm == 'yes':
|
if confirm == 'yes':
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic(using=db):
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
for sql in sql_list:
|
for sql in sql_list:
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
|
|
|
@ -981,9 +981,11 @@ class CreateCacheTableForDBCacheTests(TestCase):
|
||||||
# cache table should be created on 'other'
|
# cache table should be created on 'other'
|
||||||
# Queries:
|
# Queries:
|
||||||
# 1: check table doesn't already exist
|
# 1: check table doesn't already exist
|
||||||
# 2: create the table
|
# 2: create savepoint
|
||||||
# 3: create the index
|
# 3: create the table
|
||||||
with self.assertNumQueries(3, using='other'):
|
# 4: create the index
|
||||||
|
# 5: release savepoint
|
||||||
|
with self.assertNumQueries(5, using='other'):
|
||||||
management.call_command('createcachetable',
|
management.call_command('createcachetable',
|
||||||
database='other',
|
database='other',
|
||||||
verbosity=0, interactive=False)
|
verbosity=0, interactive=False)
|
||||||
|
|
Loading…
Reference in New Issue