diff options
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 7 | ||||
-rw-r--r-- | test/dialect/test_postgresql.py | 6 |
3 files changed, 15 insertions, 2 deletions
@@ -15,6 +15,10 @@ CHANGES fixed up some of the error messages tailored in [ticket:2069] +- postgresql + - Fixed the psycopg2_version parsing in the + psycopg2 dialect. + 0.7.0b4 ======= - general diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 2fceb7f17..2a3b4297c 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -252,10 +252,13 @@ class PGDialect_psycopg2(PGDialect): self.use_native_unicode = use_native_unicode self.supports_unicode_binds = use_native_unicode if self.dbapi and hasattr(self.dbapi, '__version__'): - m = re.match(r'(\d+)\.(\d+)\.(\d+)?', + m = re.match(r'(\d+)\.(\d+)(?:\.(\d+))?', self.dbapi.__version__) if m: - self.psycopg2_version = tuple(map(int, m.group(1, 2, 3))) + self.psycopg2_version = tuple( + int(x) + for x in m.group(1, 2, 3) + if x is not None) @classmethod def dbapi(cls): diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index e0128a77f..de7169579 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -1246,6 +1246,12 @@ class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): version) @testing.only_on('postgresql+psycopg2', 'psycopg2-specific feature') + def test_psycopg2_version(self): + v = testing.db.dialect.psycopg2_version + assert testing.db.dialect.dbapi.__version__.\ + startswith(".".join(str(x) for x in v)) + + @testing.only_on('postgresql+psycopg2', 'psycopg2-specific feature') def test_notice_logging(self): log = logging.getLogger('sqlalchemy.dialects.postgresql') buf = logging.handlers.BufferingHandler(100) |