diff mbox

[2/6] afe/readonly connection: Catch AttributeError exceptions

Message ID 1306470094-16960-3-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues May 27, 2011, 4:21 a.m. UTC
On Django 1.3, the DB connection object does not have some
of the attributes we are trying to compare on the __neq__
method, resulting on an AttributeError. Let's catch that
error so the application works under 1.3.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 frontend/afe/readonly_connection.py |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/frontend/afe/readonly_connection.py b/frontend/afe/readonly_connection.py
index 7d59aae..68af56c 100644
--- a/frontend/afe/readonly_connection.py
+++ b/frontend/afe/readonly_connection.py
@@ -89,7 +89,15 @@  class ReadOnlyConnection(object):
 
     def close(self):
         if self._connection is not None:
-            assert django_connection != self._connection
+            # Here we are checking if connection can be compared with
+            # the django DB class, but the connection class under django
+            # 1.3 doesn't have a settings_dict attribute, generating an
+            # AttributeError. So if that error is raised, supress it and
+            # only let the AssertionError pass.
+            try:
+                assert django_connection != self._connection
+            except AttributeError:
+                pass
             self._connection.close()
             self._connection = None