diff options
| author | Michael Manfre <mmanfre@gmail.com> | 2014-02-02 16:38:28 -0500 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2014-02-02 22:43:53 +0100 |
| commit | e1d839237f7ce38ef078b7f09cc3a1aeaacc02f0 (patch) | |
| tree | 89ffc517d7da805038b6c9be14fe6943090b2aab /django | |
| parent | 788cde326ae3c7bf37f98432c2994d1fb94fa41e (diff) | |
Make mysql's CursorWrapper a contextmanager.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 9d3935dc54..b752f4738f 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -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 |
