Skip to content

Commit

Permalink
Fixed drop test database command with psycopg 3 (#1818)
Browse files Browse the repository at this point in the history
Co-authored-by: Jann Haber <jann.haber@selfnet.de>
  • Loading branch information
jannh and Jann Haber committed May 24, 2023
1 parent bc43793 commit 4fc31cb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions django_extensions/management/commands/drop_test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def format_filename(name, number):
else:
import psycopg2 as Database # NOQA

conn_params = {'database': 'template1'}
conn_params = {'dbname': 'template1'}
if user:
conn_params['user'] = user
if password:
Expand All @@ -185,7 +185,10 @@ def format_filename(name, number):
conn_params['port'] = database_port

connection = Database.connect(**conn_params)
connection.set_isolation_level(0) # autocommit false
if has_psycopg3:
connection.autocommit = True
else:
connection.set_isolation_level(0) # autocommit false
cursor = connection.cursor()

for db_name in get_database_names('{}_{}'.format):
Expand Down

0 comments on commit 4fc31cb

Please sign in to comment.