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 23, 2021
1 parent 2e8ee00 commit 364ff3a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions sqlalchemy_utils/functions/database.py
Expand Up @@ -531,7 +531,11 @@ 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',
'postgresql' # Sqlalchemy uses psycopg2 if no driver is specified
}:
engine = sa.create_engine(url, isolation_level='AUTOCOMMIT')
else:
engine = sa.create_engine(url)
Expand All @@ -552,12 +556,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 364ff3a

Please sign in to comment.