Avoided transactional DDL on castrated databases.
Fixed a test failure that appeared after 753a22a6
, although the bug
existed before that commit.
Refs #22308.
This commit is contained in:
parent
6ca6c36f82
commit
0757e0f30d
|
@ -71,7 +71,9 @@ 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(using=database):
|
|
||||||
|
with transaction.atomic(using=database,
|
||||||
|
savepoint=connection.features.can_rollback_ddl):
|
||||||
with connection.cursor() as curs:
|
with connection.cursor() as curs:
|
||||||
try:
|
try:
|
||||||
curs.execute("\n".join(full_statement))
|
curs.execute("\n".join(full_statement))
|
||||||
|
@ -81,5 +83,6 @@ class Command(BaseCommand):
|
||||||
(tablename, force_text(e)))
|
(tablename, force_text(e)))
|
||||||
for statement in index_output:
|
for statement in index_output:
|
||||||
curs.execute(statement)
|
curs.execute(statement)
|
||||||
|
|
||||||
if self.verbosity > 1:
|
if self.verbosity > 1:
|
||||||
self.stdout.write("Cache table '%s' created." % tablename)
|
self.stdout.write("Cache table '%s' created." % tablename)
|
||||||
|
|
|
@ -18,7 +18,7 @@ from django.conf import settings
|
||||||
from django.core import management
|
from django.core import management
|
||||||
from django.core.cache import (cache, caches, CacheKeyWarning,
|
from django.core.cache import (cache, caches, CacheKeyWarning,
|
||||||
InvalidCacheBackendError, DEFAULT_CACHE_ALIAS)
|
InvalidCacheBackendError, DEFAULT_CACHE_ALIAS)
|
||||||
from django.db import connection, router, transaction
|
from django.db import connection, connections, router, transaction
|
||||||
from django.core.cache.utils import make_template_fragment_key
|
from django.core.cache.utils import make_template_fragment_key
|
||||||
from django.http import HttpResponse, StreamingHttpResponse
|
from django.http import HttpResponse, StreamingHttpResponse
|
||||||
from django.middleware.cache import (FetchFromCacheMiddleware,
|
from django.middleware.cache import (FetchFromCacheMiddleware,
|
||||||
|
@ -981,11 +981,12 @@ 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 savepoint
|
# 2: create savepoint (if transactional DDL is supported)
|
||||||
# 3: create the table
|
# 3: create the table
|
||||||
# 4: create the index
|
# 4: create the index
|
||||||
# 5: release savepoint
|
# 5: release savepoint (if transactional DDL is supported)
|
||||||
with self.assertNumQueries(5, using='other'):
|
num = 5 if connections['other'].features.can_rollback_ddl else 3
|
||||||
|
with self.assertNumQueries(num, 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