1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #11665 -- Made TestCase check deferrable constraints after each test.

This commit is contained in:
Jon Dufresne
2016-02-12 16:41:31 -08:00
committed by Tim Graham
parent a6f856df52
commit fcd08c1757
5 changed files with 50 additions and 2 deletions

View File

@@ -1044,7 +1044,18 @@ class TestCase(TransactionTestCase):
def _fixture_teardown(self):
if not connections_support_transactions():
return super(TestCase, self)._fixture_teardown()
self._rollback_atomics(self.atomics)
try:
for db_name in reversed(self._databases_names()):
if self._should_check_constraints(connections[db_name]):
connections[db_name].check_constraints()
finally:
self._rollback_atomics(self.atomics)
def _should_check_constraints(self, connection):
return (
connection.features.can_defer_constraint_checks and
not connection.needs_rollback and connection.is_usable()
)
class CheckCondition(object):