mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Ensure cursors are closed when no longer needed.
This commit touchs various parts of the code base and test framework. Any found usage of opening a cursor for the sake of initializing a connection has been replaced with 'ensure_connection()'.
This commit is contained in:
@@ -202,8 +202,9 @@ class AtomicTests(TransactionTestCase):
|
||||
# trigger a database error inside an inner atomic without savepoint
|
||||
with self.assertRaises(DatabaseError):
|
||||
with transaction.atomic(savepoint=False):
|
||||
connection.cursor().execute(
|
||||
"SELECT no_such_col FROM transactions_reporter")
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
"SELECT no_such_col FROM transactions_reporter")
|
||||
# prevent atomic from rolling back since we're recovering manually
|
||||
self.assertTrue(transaction.get_rollback())
|
||||
transaction.set_rollback(False)
|
||||
@@ -534,8 +535,8 @@ class TransactionRollbackTests(IgnoreDeprecationWarningsMixin, TransactionTestCa
|
||||
available_apps = ['transactions']
|
||||
|
||||
def execute_bad_sql(self):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
|
||||
|
||||
@skipUnlessDBFeature('requires_rollback_on_dirty_transaction')
|
||||
def test_bad_sql(self):
|
||||
@@ -678,6 +679,6 @@ class TransactionContextManagerTests(IgnoreDeprecationWarningsMixin, Transaction
|
||||
"""
|
||||
with self.assertRaises(IntegrityError):
|
||||
with transaction.commit_on_success():
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
|
||||
transaction.rollback()
|
||||
|
||||
Reference in New Issue
Block a user