From 3ffeb931869cc68a8e0916219702ee282afc6e9d Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Thu, 9 Jan 2014 10:05:15 -0500 Subject: 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()'. --- django/db/backends/postgresql_psycopg2/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'django/db/backends/postgresql_psycopg2/base.py') diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 33f885d50c..e89a4e604a 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -149,8 +149,10 @@ class DatabaseWrapper(BaseDatabaseWrapper): if conn_tz != tz: cursor = self.connection.cursor() - cursor.execute(self.ops.set_time_zone_sql(), [tz]) - cursor.close() + try: + cursor.execute(self.ops.set_time_zone_sql(), [tz]) + finally: + cursor.close() # Commit after setting the time zone (see #17062) if not self.get_autocommit(): self.connection.commit() -- cgit v1.3