1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

[soc2010/query-refactor] Ensure that calling close() doesn't blow up if a connection was never opened.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13432 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2010-07-17 02:20:29 +00:00
parent 536a5ca514
commit 59089a7d13
2 changed files with 9 additions and 2 deletions

View File

@ -76,6 +76,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
return self.connection[self.settings_dict["NAME"]]
def close(self):
if self._connection is not None:
self._connection.disconnect()
self._connection = None

View File

@ -1,3 +1,4 @@
from django.db import connection
from django.db.models import Count, F
from django.test import TestCase
@ -337,3 +338,8 @@ class MongoTestCase(TestCase):
],
lambda g: g.name,
)
def test_close(self):
# Ensure that closing a connection that was never established doesn't
# blow up.
connection.close()