# HG changeset patch # User Daniele Nicolodi # Date 1323702707 -3600 # Node ID 16f095c747066dcfe0d2525dc09562c5dd2416c0 # Parent 39b50b763f11e89d97ceae129eba0f13ad664f47 Make collections upgrade step more robust. diff -r 39b50b763f11 -r 16f095c74706 src/ltpdarepo/upgrade.py --- a/src/ltpdarepo/upgrade.py Mon Dec 12 15:10:28 2011 +0100 +++ b/src/ltpdarepo/upgrade.py Mon Dec 12 16:11:47 2011 +0100 @@ -504,15 +504,19 @@ for id, nobjs, obj_ids in curs.fetchall(): ids = map(int, obj_ids.split(',')) if len(ids) != nobjs: - logger.warning(" bad collection description cid=%d", id) + logger.warning(" bad collection description %d", id) # discard collections composed by a single object if len(ids) == 1: - logger.info(" deleting single object collection cid=%d", id) + logger.info(" deleting single object collection %d", id) curs.execute("""DELETE FROM collections WHERE id=%s""", id) continue for obj_id in ids: - curs.execute("""INSERT INTO collections2objs (id, obj_id) - VALUES (%s, %s)""", (id, obj_id)) + try: + curs.execute("""INSERT INTO collections2objs (id, obj_id) + VALUES (%s, %s)""", (id, obj_id)) + except mysql.IntegrityError: + logger.warning(" ignoring non existent object %d " + "in collection %d", obj_id, id) # drop old columns curs.execute("""ALTER TABLE collections DROP COLUMN nobjs""")