← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~lgp171188/launchpad:fix-vulnerabilitysubscription-person-unique-index into launchpad:db-devel

 

Guruprasad has proposed merging ~lgp171188/launchpad:fix-vulnerabilitysubscription-person-unique-index into launchpad:db-devel.

Commit message:
Fix the personmerge test failures due to unhandled unique index reference

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~lgp171188/launchpad/+git/launchpad/+merge/427259
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~lgp171188/launchpad:fix-vulnerabilitysubscription-person-unique-index into launchpad:db-devel.
diff --git a/lib/lp/registry/personmerge.py b/lib/lp/registry/personmerge.py
index 2cef92b..9a2729d 100644
--- a/lib/lp/registry/personmerge.py
+++ b/lib/lp/registry/personmerge.py
@@ -727,6 +727,24 @@ def _mergeOCIRecipeSubscription(cur, from_id, to_id):
         ''' % vars())
 
 
+def _mergeVulnerabilitySubscription(cur, from_id, to_id):
+    # Update only the VulnerabilitySubscription that will not conflict.
+    cur.execute('''
+        UPDATE VulnerabilitySubscription
+        SET person=%(to_id)d
+        WHERE person=%(from_id)d AND vulnerability NOT IN
+            (
+            SELECT vulnerability
+            FROM VulnerabilitySubscription
+            WHERE person = %(to_id)d
+            )
+    ''' % vars())
+    # and delete those left over.
+    cur.execute('''
+        DELETE FROM VulnerabilitySubscription WHERE person=%(from_id)d
+        ''' % vars())
+
+
 def _mergeCharmRecipe(cur, from_person, to_person):
     # This shouldn't use removeSecurityProxy.
     recipes = getUtility(ICharmRecipeSet).findByOwner(from_person)
@@ -980,6 +998,9 @@ def merge_people(from_person, to_person, reviewer, delete=False):
     _mergeCharmRecipe(cur, from_id, to_id)
     skip.append(('charmrecipe', 'owner'))
 
+    _mergeVulnerabilitySubscription(cur, from_id, to_id)
+    skip.append(('vulnerabilitysubscription', 'person'))
+
     # Sanity check. If we have a reference that participates in a
     # UNIQUE index, it must have already been handled by this point.
     # We can tell this by looking at the skip list.

Follow ups