Fixed #30023 -- Prevented SQLite schema alterations while foreign key checks are enabled.

Prior to this change foreign key constraint references could be left pointing
at tables dropped during operations simulating unsupported table alterations
because of an unexpected failure to disable foreign key constraint checks.

SQLite3 does not allow disabling such checks while in a transaction so they
must be disabled beforehand.

Thanks ezaquarii for the report and Carlton and Tim for the review.
This commit is contained in:
Simon Charette 2018-12-07 19:55:47 -05:00
parent a394289b58
commit 315357ad25
8 changed files with 89 additions and 42 deletions

View file

@ -11,9 +11,7 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django.core.management.base import SystemCheckError
from django.test import (
TestCase, TransactionTestCase, skipUnlessDBFeature, testcases,
)
from django.test import TransactionTestCase, skipUnlessDBFeature, testcases
from django.test.runner import DiscoverRunner
from django.test.testcases import connections_support_transactions
from django.test.utils import dependency_ordered
@ -242,8 +240,9 @@ class Ticket17477RegressionTests(AdminScriptTestCase):
self.assertNoOutput(err)
class Sqlite3InMemoryTestDbs(TestCase):
class Sqlite3InMemoryTestDbs(TransactionTestCase):
multi_db = True
available_apps = ['test_runner']
@unittest.skipUnless(all(db.connections[conn].vendor == 'sqlite' for conn in db.connections),
"This is an sqlite-specific issue")