Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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
  • Loading branch information...
commit 59089a7d1384f5697e75c55f95a10e721757e2e7 1 parent 536a5ca
@alex alex authored
View
5 django/contrib/mongodb/base.py
@@ -76,8 +76,9 @@ def db(self):
return self.connection[self.settings_dict["NAME"]]
def close(self):
- self._connection.disconnect()
- self._connection = None
+ if self._connection is not None:
+ self._connection.disconnect()
+ self._connection = None
###########################
View
6 tests/regressiontests/mongodb/tests.py
@@ -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 @@ def test_regex(self):
],
lambda g: g.name,
)
+
+ def test_close(self):
+ # Ensure that closing a connection that was never established doesn't
+ # blow up.
+ connection.close()
Please sign in to comment.
Something went wrong with that request. Please try again.