diff options
author | Michael Manfre <mmanfre@gmail.com> | 2014-01-09 10:05:15 -0500 |
---|---|---|
committer | Michael Manfre <mmanfre@gmail.com> | 2014-02-02 12:47:21 -0500 |
commit | 3ffeb931869cc68a8e0916219702ee282afc6e9d (patch) | |
tree | f24020307dd5b529989329bfabfc95effcecffe8 /tests/custom_methods | |
parent | 0837eacc4e1fa7916e48135e8ba43f54a7a64997 (diff) | |
download | django-3ffeb931869cc68a8e0916219702ee282afc6e9d.tar.gz |
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()'.
Diffstat (limited to 'tests/custom_methods')
-rw-r--r-- | tests/custom_methods/models.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/custom_methods/models.py b/tests/custom_methods/models.py index cef3fd722b..78e00a99b8 100644 --- a/tests/custom_methods/models.py +++ b/tests/custom_methods/models.py @@ -30,11 +30,11 @@ class Article(models.Model): database query for the sake of demonstration. """ from django.db import connection - cursor = connection.cursor() - cursor.execute(""" - SELECT id, headline, pub_date - FROM custom_methods_article - WHERE pub_date = %s - AND id != %s""", [connection.ops.value_to_db_date(self.pub_date), - self.id]) - return [self.__class__(*row) for row in cursor.fetchall()] + with connection.cursor() as cursor: + cursor.execute(""" + SELECT id, headline, pub_date + FROM custom_methods_article + WHERE pub_date = %s + AND id != %s""", [connection.ops.value_to_db_date(self.pub_date), + self.id]) + return [self.__class__(*row) for row in cursor.fetchall()] |