Skip to content

Commit

Permalink
Fix isolation level bug with psycopg2
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Lumia committed Jan 22, 2021
1 parent 2e8ee00 commit b85ffce
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions sqlalchemy_utils/functions/database.py
Expand Up @@ -531,7 +531,7 @@ def create_database(url, encoding='utf8', template=None):

if url.drivername == 'mssql+pyodbc':
engine = sa.create_engine(url, connect_args={'autocommit': True})
elif url.drivername == 'postgresql+pg8000':
elif url.drivername in {'postgresql+pg8000', 'postgresql+psycopg2'}:
engine = sa.create_engine(url, isolation_level='AUTOCOMMIT')
else:
engine = sa.create_engine(url)
Expand All @@ -552,12 +552,6 @@ def create_database(url, encoding='utf8', template=None):
connection.connection.set_session(autocommit=True)
connection.execute(text)
else:
if engine.driver == 'psycopg2':
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
engine.raw_connection().set_isolation_level(
ISOLATION_LEVEL_AUTOCOMMIT
)

result_proxy = engine.execute(text)

elif engine.dialect.name == 'mysql':
Expand Down

0 comments on commit b85ffce

Please sign in to comment.