]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Make pg8000 version detection more robust
authorTony Locke <tlocke@tlocke.org.uk>
Sun, 24 Aug 2014 14:15:17 +0000 (15:15 +0100)
committerTony Locke <tlocke@tlocke.org.uk>
Tue, 16 Dec 2014 21:03:04 +0000 (21:03 +0000)
pg8000 uses Versioneer, which means that development versions have
version strings that don't fit into the dotted triple number format.
Released versions will always fit the triple format though.

lib/sqlalchemy/dialects/postgresql/pg8000.py

index a7678701686a23f81803eaadb40b8ae7ae997acf..17d83fa6166c7f19ca6f268ceb1ed30f0e2017c9 100644 (file)
@@ -71,6 +71,7 @@ from ... import types as sqltypes
 from .base import (
     PGDialect, PGCompiler, PGIdentifierPreparer, PGExecutionContext,
     _DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES)
+import re
 
 
 class _PGNumeric(sqltypes.Numeric):
@@ -151,15 +152,19 @@ class PGDialect_pg8000(PGDialect):
         self.client_encoding = client_encoding
 
     def initialize(self, connection):
-        if self.dbapi and hasattr(self.dbapi, '__version__'):
-            self._dbapi_version = tuple([
-                int(x) for x in
-                self.dbapi.__version__.split(".")])
-        else:
-            self._dbapi_version = (99, 99, 99)
         self.supports_sane_multi_rowcount = self._dbapi_version >= (1, 9, 14)
         super(PGDialect_pg8000, self).initialize(connection)
 
+    @util.memoized_property
+    def _dbapi_version(self):
+        if self.dbapi and hasattr(self.dbapi, '__version__'):
+            return tuple(
+                [
+                    int(x) for x in re.findall(
+                        r'(\d+)(?:[-\.]?|$)', self.dbapi.__version__)])
+        else:
+            return (99, 99, 99)
+
     @classmethod
     def dbapi(cls):
         return __import__('pg8000')