From 0ddf72b323466ef4bfe84136c7a38d020254d41f Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 10 Jan 2015 17:58:00 +0100 Subject: [PATCH] avoid transaction for CREATE and DROP database --- gvapgsql/pgsqltasks/tasks.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/gvapgsql/pgsqltasks/tasks.py b/gvapgsql/pgsqltasks/tasks.py index 8c11cde..1683ff5 100644 --- a/gvapgsql/pgsqltasks/tasks.py +++ b/gvapgsql/pgsqltasks/tasks.py @@ -135,13 +135,14 @@ def create_pgsql_database(dbname, username): """ with _get_connection() as conn: - with conn.cursor() as curs: - curs.execute( - """ - CREATE DATABASE %(dbname)s OWNER %(username)s - """, - {'dbname': Ident(dbname), 'username': Ident(username)} - ) + conn.autocommit = True + curs = conn.cursor() + curs.execute( + """ + CREATE DATABASE %(dbname)s OWNER %(username)s + """, + {'dbname': Ident(dbname), 'username': Ident(username)} + ) @shared_task @@ -155,10 +156,11 @@ def delete_pgsql_database(dbname): """ with _get_connection() as conn: - with conn.cursor() as curs: - curs.execute( - """ - DROP DATABASE %(dbname)s - """, - {'dbname': Ident(dbname)} - ) + conn.autocommit = True + curs = conn.cursor() + curs.execute( + """ + DROP DATABASE %(dbname)s + """, + {'dbname': Ident(dbname)} + )