From ac0c988603673d367b7985a962c1d1437e350564 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 2 Feb 2015 09:54:50 -0800 Subject: [PATCH] Fix approval sync We're treating some fields in the db as if they have a unique constraint, but there is no actual unique constraint in the db. If, somehow, we ended up with multiple approvals for the same user associated with a change, then the correct values may not be displayed in the change approval table. Correct this by detecting when we have multiple local entries for an approval and remove entries subsequent to the first. The first entry will remain and either be removed or have its value updated as necessary. Change-Id: Ifdc6273f1d5d4e83124ec30ff454c46e3e3af2d3 --- gertty/sync.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gertty/sync.py b/gertty/sync.py index 0c89d8d..f036bbd 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -489,7 +489,10 @@ class SyncChangeTask(Task): local_labels = {} for approval in change.approvals: key = '%s~%s' % (approval.category, approval.reviewer.id) - local_approvals[key] = approval + if key in local_approvals: + session.delete(approval) + else: + local_approvals[key] = approval local_approval_keys = set(local_approvals.keys()) for label in change.labels: key = '%s~%s~%s' % (label.category, label.value, label.description)