Index: roundup/backends/back_postgresql.py =================================================================== RCS file: /cvsroot/roundup/roundup/roundup/backends/back_postgresql.py,v retrieving revision 1.44 diff -u -r1.44 back_postgresql.py --- roundup/backends/back_postgresql.py 7 Aug 2008 05:50:03 -0000 1.44 +++ roundup/backends/back_postgresql.py 1 Sep 2008 10:07:36 -0000 @@ -11,13 +11,13 @@ import os, shutil, popen2, time try: - import psycopg - from psycopg import QuotedString - from psycopg import ProgrammingError -except: - from psycopg2 import psycopg1 as psycopg + from psycopg2 import psycopg1 as psycopg from psycopg2.extensions import QuotedString - from psycopg2.psycopg1 import ProgrammingError + from psycopg2.psycopg1 import ProgrammingError +except ImportError: + import psycopg + from psycopg import QuotedString + from psycopg import ProgrammingError import logging from roundup import hyperdb, date @@ -78,23 +78,18 @@ ''' try: cursor.execute(command) - except psycopg.ProgrammingError, err: + except psycopg.DatabaseError, err: response = str(err).split('\n')[0] - if response.find('FATAL') != -1: - raise RuntimeError, response - else: - msgs = [ + if "FATAL" not in response : + msgs = ( 'is being accessed by other users', - 'could not serialize access due to concurrent update', - ] - can_retry = 0 - for msg in msgs: - if response.find(msg) == -1: - can_retry = 1 - if can_retry: - time.sleep(1) - return 0 - raise RuntimeError, response + 'could not serialize access due to concurrent update' + ) + for msg in msgs : + if msg in response : + time.sleep(0.1) + return 0 + raise RuntimeError (response) return 1 def db_exists(config): @@ -149,7 +144,7 @@ try: self.load_dbschema() - except psycopg.ProgrammingError, message: + except ProgrammingError, message: if str(message).find('schema') == -1: raise self.rollback() @@ -222,7 +217,7 @@ try: self.conn.commit() - except psycopg.ProgrammingError, message: + except ProgrammingError, message: # we've been instructed that this commit is allowed to fail if fail_ok and str(message).endswith('could not serialize ' 'access due to concurrent update'):