Commits

Anonymous committed 06d252c

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

  • Participants
  • Parent commits 3edd2cd
  • Branches soc2010/query-refactor

Comments (0)

Files changed (2)

django/contrib/mongodb/base.py

         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
     
     
     ###########################

tests/regressiontests/mongodb/tests.py

+from django.db import connection
 from django.db.models import Count, F
 from django.test import TestCase
 
             ],
             lambda g: g.name,
         )
+    
+    def test_close(self):
+        # Ensure that closing a connection that was never established doesn't
+        # blow up.
+        connection.close()