1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Make mysql's CursorWrapper a contextmanager.

This commit is contained in:
Michael Manfre
2014-02-02 16:38:28 -05:00
committed by Aymeric Augustin
parent 788cde326a
commit e1d839237f
2 changed files with 10 additions and 2 deletions

View File

@@ -152,6 +152,14 @@ class CursorWrapper(object):
def __iter__(self):
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):
empty_fetchmany_value = ()
@@ -461,7 +469,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
return conn
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
# 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