From 3e5200dbd511736e3144ee0ddef1289a7df3affe Mon Sep 17 00:00:00 2001 From: ber Date: Fri, 1 Jul 2011 15:05:09 +0000 Subject: [PATCH] PostgreSQL backend minor improvement: database creation less likely to fail for PostgreSQL versions >= 8.1 as the table "postgres" is used by default. Closes issue2550543. Thanks to Kai Storbeck for the patch. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4626 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 3 +++ roundup/backends/back_postgresql.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7a8597a..5968793 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,9 @@ Features: - Xapian indexing improved: Slightly faster and slightly smaller database. Closes issue2550687. Thanks to Olly Betts for the patch. (Bernhard Reiter) +- PostgreSQL backend minor improvement: database creation less likely to fail + for PostgreSQL versions >= 8.1 as the table "postgres" is used by default. + Closes issue2550543. Thanks to Kai Storbeck for the patch. (Bernhard Reiter) Fixed: diff --git a/roundup/backends/back_postgresql.py b/roundup/backends/back_postgresql.py index 0981262..defa905 100644 --- a/roundup/backends/back_postgresql.py +++ b/roundup/backends/back_postgresql.py @@ -50,16 +50,22 @@ def db_nuke(config, fail_ok=0): if os.path.exists(config.DATABASE): shutil.rmtree(config.DATABASE) -def db_command(config, command): +def db_command(config, command, database='postgres'): '''Perform some sort of database-level command. Retry 10 times if we fail by conflicting with another user. + + Since PostgreSQL version 8.1 there is a database "postgres", + before "template1" seems to habe been used, so we fall back to it. + Compare to issue2550543. ''' template1 = connection_dict(config) - template1['database'] = 'template1' + template1['database'] = database try: conn = psycopg.connect(**template1) except psycopg.OperationalError, message: + if str(message).find('database "postgres" does not exist') >= 0: + return db_command(config, command, database='template1') raise hyperdb.DatabaseError(message) conn.set_isolation_level(0) -- 2.30.2