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:
parent
536a5ca514
commit
59089a7d13
@ -76,8 +76,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||||||
return self.connection[self.settings_dict["NAME"]]
|
return self.connection[self.settings_dict["NAME"]]
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self._connection.disconnect()
|
if self._connection is not None:
|
||||||
self._connection = None
|
self._connection.disconnect()
|
||||||
|
self._connection = None
|
||||||
|
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from django.db import connection
|
||||||
from django.db.models import Count, F
|
from django.db.models import Count, F
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
@ -337,3 +338,8 @@ class MongoTestCase(TestCase):
|
|||||||
],
|
],
|
||||||
lambda g: g.name,
|
lambda g: g.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_close(self):
|
||||||
|
# Ensure that closing a connection that was never established doesn't
|
||||||
|
# blow up.
|
||||||
|
connection.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user