From: Mike Bayer Date: Mon, 18 Apr 2011 16:38:08 +0000 (-0400) Subject: - Fixed the psycopg2_version parsing in the X-Git-Tag: rel_0_7_0~49^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c718dea749204169db2b49ea5d18248cbfe6c76f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed the psycopg2_version parsing in the psycopg2 dialect. --- diff --git a/CHANGES b/CHANGES index a781307b42..72fc038c12 100644 --- a/CHANGES +++ b/CHANGES @@ -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 2fceb7f17d..2a3b4297c3 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 e0128a77f2..de71695793 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -1245,6 +1245,12 @@ class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): eq_(testing.db.dialect._get_server_version_info(MockConn(string)), 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')