Make mysql's CursorWrapper a contextmanager.
This commit is contained in:
parent
788cde326a
commit
e1d839237f
|
@ -152,6 +152,14 @@ class CursorWrapper(object):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.cursor)
|
return iter(self.cursor)
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
# Ticket #17671 - Close instead of passing thru to avoid backend
|
||||||
|
# specific behavior.
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
class DatabaseFeatures(BaseDatabaseFeatures):
|
class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
empty_fetchmany_value = ()
|
empty_fetchmany_value = ()
|
||||||
|
@ -461,7 +469,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
def init_connection_state(self):
|
def init_connection_state(self):
|
||||||
with self.connection.cursor() as cursor:
|
with self.cursor() as cursor:
|
||||||
# SQL_AUTO_IS_NULL in MySQL controls whether an AUTO_INCREMENT column
|
# SQL_AUTO_IS_NULL in MySQL controls whether an AUTO_INCREMENT column
|
||||||
# on a recently-inserted row will return when the field is tested for
|
# on a recently-inserted row will return when the field is tested for
|
||||||
# NULL. Disabling this value brings this aspect of MySQL in line with
|
# NULL. Disabling this value brings this aspect of MySQL in line with
|
||||||
|
|
|
@ -725,7 +725,7 @@ class DatabaseConnectionHandlingTests(TransactionTestCase):
|
||||||
# request_finished signal.
|
# request_finished signal.
|
||||||
response = self.client.get('/')
|
response = self.client.get('/')
|
||||||
# Make sure there is an open connection
|
# Make sure there is an open connection
|
||||||
self.connection.ensure_connection()
|
connection.ensure_connection()
|
||||||
connection.enter_transaction_management()
|
connection.enter_transaction_management()
|
||||||
signals.request_finished.send(sender=response._handler_class)
|
signals.request_finished.send(sender=response._handler_class)
|
||||||
self.assertEqual(len(connection.transaction_state), 0)
|
self.assertEqual(len(connection.transaction_state), 0)
|
||||||
|
|
Loading…
Reference in New Issue