From fe889944d02b3720297425133b069e4e7a7b762f Mon Sep 17 00:00:00 2001 From: al-niessner <1130658+al-niessner@users.noreply.github.com> Date: Thu, 13 Oct 2022 13:14:05 -0700 Subject: [PATCH] issue_186: maybe fix timelines (#188) * maybe fix timelines Could not exactly replicate the error in the log file but found a simple error and repaired it. Given how algorithm and sv PKs work, it is necessary to allow multiples and then work with the latest in the database (largest primary table PK). * fixed timelines The notebook page was running with the older psycopg2 which worked. Moved to the correct psycopg (3.1.9) and duplicated the error. Corrected it code using fetchall() as it now returns a list of tuples. --- Python/dawgie/db/post.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Python/dawgie/db/post.py b/Python/dawgie/db/post.py index 2f3b8c13..492e6388 100644 --- a/Python/dawgie/db/post.py +++ b/Python/dawgie/db/post.py @@ -374,11 +374,11 @@ def _recede (self, refs:[(dawgie.SV_REF, dawgie.V_REF)])->None: cur.execute('SELECT PK from Algorithm WHERE name = %s and ' + 'task_ID = %s;', (ref.impl.name(), task_ID,)) - alg_IDs = cur.fetchall() + alg_IDs = [aid[0] for aid in cur.fetchall()] cur.execute('SELECT PK FROM StateVector WHERE name = %s and ' + 'alg_ID = ANY(%s);', (ref.item.name(), alg_IDs,)) - sv_IDs = cur.fetchall() + sv_IDs = [svid[0] for svid in cur.fetchall()] fsvn = '.'.join ([dawgie.util.task_name (ref.factory), ref.impl.name(), ref.item.name()]) @@ -387,20 +387,14 @@ def _recede (self, refs:[(dawgie.SV_REF, dawgie.V_REF)])->None: 'sv_ID = ANY(%s);', [tnid, task_ID, alg_IDs, sv_IDs]) rids = sorted ({r[0] for r in cur.fetchall()}) for rid in rids: - cur.execute ('SELECT alg_ID,sv_ID FROM Prime WHERE ' + + cur.execute ('SELECT PK,alg_ID,sv_ID FROM Prime WHERE ' + 'run_ID = %s AND tn_ID = %s AND ' + 'task_ID = %s AND alg_ID = ANY(%s) AND ' + 'sv_ID = ANY(%s);', [rid, tnid, task_ID, alg_IDs, sv_IDs]) ids = cur.fetchall() - aids = {id[0] for id in ids} - svids = {id[1] for id in ids} - - if len (aids) != 1 and len (svids) != 1: - log.critical ('Database corruption from many versions at one run id.') - continue - - alg_ID,sv_ID = aids.pop(),svids.pop() + pks = [id[0] for id in ids] + alg_ID,sv_ID = ids[pks.index(max(pks))][1:] cur.execute('SELECT val_ID from Prime WHERE run_ID = %s AND ' + 'alg_ID = %s AND tn_ID = %s and task_ID = %s and ' + 'sv_ID = %s;',