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
This commit is contained in:
James E. Blair 2015-02-02 09:54:50 -08:00
parent ac6b77c71e
commit ac0c988603
1 changed files with 4 additions and 1 deletions

View File

@ -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)