From 7a3a446d02b2155001b08af3f0e6d08fe3dc809b Mon Sep 17 00:00:00 2001 From: mike bayer Date: Sat, 15 Jun 2013 19:52:00 -0700 Subject: [PATCH] Merge pull request #7 from malor/psycopg2_execution_options Add AUTOCOMMIT isolation level support for psycopg2 --- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 1 + test/dialect/test_postgresql.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index c796c99c73..2d475ccda0 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -351,6 +351,7 @@ class PGDialect_psycopg2(PGDialect): def _isolation_lookup(self): extensions = __import__('psycopg2.extensions').extensions return { + 'AUTOCOMMIT': extensions.ISOLATION_LEVEL_AUTOCOMMIT, 'READ COMMITTED': extensions.ISOLATION_LEVEL_READ_COMMITTED, 'READ UNCOMMITTED': extensions.ISOLATION_LEVEL_READ_UNCOMMITTED, 'REPEATABLE READ': extensions.ISOLATION_LEVEL_REPEATABLE_READ, diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index a8003e9736..43c4719190 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -1889,6 +1889,16 @@ class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): c = e.connect() eq_(c.connection.connection.encoding, test_encoding) + @testing.only_on('postgresql+psycopg2', 'psycopg2-specific feature') + @engines.close_open_connections + def test_autocommit_isolation_level(self): + extensions = __import__('psycopg2.extensions').extensions + + c = testing.db.connect() + c = c.execution_options(isolation_level='AUTOCOMMIT') + eq_(c.connection.connection.isolation_level, + extensions.ISOLATION_LEVEL_AUTOCOMMIT) + @testing.fails_on('+zxjdbc', "Can't infer the SQL type to use for an instance " "of org.python.core.PyObjectDerived.") -- 2.47.2