Skip to content

Commit 59089a7

Browse files
committed
[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
1 parent 536a5ca commit 59089a7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

django/contrib/mongodb/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ def db(self):
7676
return self.connection[self.settings_dict["NAME"]]
7777

7878
def close(self):
79-
self._connection.disconnect()
80-
self._connection = None
79+
if self._connection is not None:
80+
self._connection.disconnect()
81+
self._connection = None
8182

8283

8384
###########################

tests/regressiontests/mongodb/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.db import connection
12
from django.db.models import Count, F
23
from django.test import TestCase
34

@@ -337,3 +338,8 @@ def test_regex(self):
337338
],
338339
lambda g: g.name,
339340
)
341+
342+
def test_close(self):
343+
# Ensure that closing a connection that was never established doesn't
344+
# blow up.
345+
connection.close()

0 commit comments

Comments
 (0)