]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed the import for entrypoint-driven dialects to
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 5 Dec 2009 00:36:11 +0000 (00:36 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 5 Dec 2009 00:36:11 +0000 (00:36 +0000)
not rely upon silly tb_info trick to determine import
error status.  [ticket:1630]

CHANGES
lib/sqlalchemy/engine/url.py

diff --git a/CHANGES b/CHANGES
index 052848fbf94b582b13abc7fa560f01939090105a..1628f5c70b865403c7284bbd8d6536aca23bc2a3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -259,7 +259,11 @@ CHANGES
   - transaction isolation level may be specified with
     create_engine(... isolation_level="..."); available on
     postgresql and sqlite. [ticket:443]
-
+  
+  - fixed the import for entrypoint-driven dialects to 
+    not rely upon silly tb_info trick to determine import
+    error status.  [ticket:1630]
+    
   - added first() method to ResultProxy, returns first row and
     closes result set immediately.
 
index c62f1cf101de0f542a5fb7baba60c7f3b14108fc..5d658d7fc6271149a88ec1d31b50898ec497e1c4 100644 (file)
@@ -102,13 +102,30 @@ class URL(object):
 
             return module.dialect
         except ImportError:
-            if sys.exc_info()[2].tb_next is None:
-                import pkg_resources
-                for res in pkg_resources.iter_entry_points('sqlalchemy.dialects'):
-                    if res.name == self.drivername:
-                        return res.load()
-            raise
-
+            module = self._load_entry_point()
+            if module is not None:
+                return module
+            else:
+                raise
+    
+    def _load_entry_point(self):
+        """attempt to load this url's dialect from entry points, or return None
+        if pkg_resources is not installed or there is no matching entry point.
+        
+        Raise ImportError if the actual load fails.
+        
+        """
+        try:
+            import pkg_resources
+        except ImportError:
+            return None
+            
+        for res in pkg_resources.iter_entry_points('sqlalchemy.dialects'):
+            if res.name == self.drivername:
+                return res.load()
+        else:
+            return None
+        
     def translate_connect_args(self, names=[], **kw):
         """Translate url attributes into a dictionary of connection arguments.