1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #31233 -- Closed database connections and cursors after use.

This commit is contained in:
Jon Dufresne
2020-02-03 19:07:00 -08:00
committed by Mariusz Felisiak
parent f48f671223
commit 3259983f56
14 changed files with 86 additions and 55 deletions

View File

@@ -564,7 +564,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# This won't affect other tests because the database connection
# is closed at the end of each test.
if connection.vendor == 'mysql':
connection.cursor().execute("SET sql_mode = 'TRADITIONAL'")
with connection.cursor() as cursor:
cursor.execute("SET sql_mode = 'TRADITIONAL'")
with self.assertRaises(IntegrityError) as cm:
management.call_command('loaddata', 'invalid.json', verbosity=0)
self.assertIn("Could not load fixtures.Article(pk=1):", cm.exception.args[0])