From: Mike Bayer Date: Sat, 5 Dec 2009 00:36:11 +0000 (+0000) Subject: - fixed the import for entrypoint-driven dialects to X-Git-Tag: rel_0_6beta1~148 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ffdbcbc89a2ac12be499944195572d3014b34061;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fixed the import for entrypoint-driven dialects to not rely upon silly tb_info trick to determine import error status. [ticket:1630] --- diff --git a/CHANGES b/CHANGES index 052848fbf9..1628f5c70b 100644 --- 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. diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py index c62f1cf101..5d658d7fc6 100644 --- a/lib/sqlalchemy/engine/url.py +++ b/lib/sqlalchemy/engine/url.py @@ -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.