From bebc0055ecf573e0fa2fd663d8e6d52c5f8f1cdc Mon Sep 17 00:00:00 2001 From: Allan Lyons Date: Fri, 1 May 2009 12:28:47 -0600 Subject: [PATCH] Check for the existance of the function before trying to drop it. At least on my machine, ignoring the error if the function doesn't exist doesn't work since psycopg2 bombs. So, we attempt to at least check if there are any functions with a similar name before trying to drop it. This way it should work better on an empty database where the function has never existed. Signed-off-by: Allan Lyons --- dak/dakdb/update3.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dak/dakdb/update3.py b/dak/dakdb/update3.py index 406cc89b..5a5562fb 100755 --- a/dak/dakdb/update3.py +++ b/dak/dakdb/update3.py @@ -36,12 +36,15 @@ def do_update(self): try: c = self.db.cursor() - try: - # This might not exist on a fresh install, so don't fail - # needlessly + # The reason we try and check to see if it exists is that + # psycopg2 might leave the cursor invalid if the drop fails + c.execute("SELECT proname from pg_catalog.pg_proc WHERE proname = 'versioncmp'") + rows = c.fetchall() + if rows: c.execute("DROP FUNCTION versioncmp(text, text);") - except: - pass + else: + print "function already does not exist" + c.execute("UPDATE config SET value = '3' WHERE name = 'db_revision'") self.db.commit() -- 2.39.5