Author: Alex
Date: 2010-07-16 21:20:29 -0500 (Fri, 16 Jul 2010)
New Revision: 13432

Modified:
   django/branches/soc2010/query-refactor/django/contrib/mongodb/base.py
   django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py
Log:
[soc2010/query-refactor] Ensure that calling close() doesn't blow up if a 
connection was never opened.

Modified: django/branches/soc2010/query-refactor/django/contrib/mongodb/base.py
===================================================================
--- django/branches/soc2010/query-refactor/django/contrib/mongodb/base.py       
2010-07-13 19:33:43 UTC (rev 13431)
+++ django/branches/soc2010/query-refactor/django/contrib/mongodb/base.py       
2010-07-17 02:20:29 UTC (rev 13432)
@@ -76,8 +76,9 @@
         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
     
     
     ###########################

Modified: 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py
===================================================================
--- 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py   
    2010-07-13 19:33:43 UTC (rev 13431)
+++ 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py   
    2010-07-17 02:20:29 UTC (rev 13432)
@@ -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 @@
             ],
             lambda g: g.name,
         )
+    
+    def test_close(self):
+        # Ensure that closing a connection that was never established doesn't
+        # blow up.
+        connection.close()

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to