diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/asyncpg.py | 15 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/provision.py | 13 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py index 569024790..412feda0f 100644 --- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py +++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py @@ -491,7 +491,7 @@ class AsyncAdapt_asyncpg_connection: def __init__(self, dbapi, connection): self.dbapi = dbapi self._connection = connection - self.isolation_level = "read_committed" + self.isolation_level = self._isolation_setting = "read_committed" self.readonly = False self.deferrable = False self._transaction = None @@ -512,10 +512,21 @@ class AsyncAdapt_asyncpg_connection: else: raise error + @property + def autocommit(self): + return self.isolation_level == "autocommit" + + @autocommit.setter + def autocommit(self, value): + if value: + self.isolation_level = "autocommit" + else: + self.isolation_level = self._isolation_setting + def set_isolation_level(self, level): if self._started: self.rollback() - self.isolation_level = level + self.isolation_level = self._isolation_setting = level async def _start_transaction(self): if self.isolation_level == "autocommit": diff --git a/lib/sqlalchemy/dialects/postgresql/provision.py b/lib/sqlalchemy/dialects/postgresql/provision.py index 6c6dc4be6..9433ec458 100644 --- a/lib/sqlalchemy/dialects/postgresql/provision.py +++ b/lib/sqlalchemy/dialects/postgresql/provision.py @@ -5,6 +5,7 @@ from ... import text from ...testing.provision import create_db from ...testing.provision import drop_db from ...testing.provision import log +from ...testing.provision import set_default_schema_on_connection from ...testing.provision import temp_table_keyword_args @@ -64,3 +65,15 @@ def _pg_drop_db(cfg, eng, ident): @temp_table_keyword_args.for_db("postgresql") def _postgresql_temp_table_keyword_args(cfg, eng): return {"prefixes": ["TEMPORARY"]} + + +@set_default_schema_on_connection.for_db("postgresql") +def _postgresql_set_default_schema_on_connection( + cfg, dbapi_connection, schema_name +): + existing_autocommit = dbapi_connection.autocommit + dbapi_connection.autocommit = True + cursor = dbapi_connection.cursor() + cursor.execute("SET SESSION search_path='%s'" % schema_name) + cursor.close() + dbapi_connection.autocommit = existing_autocommit |
