← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pelpsi/launchpad:send-bug-notifications-opsees-list-index-out-of-range into launchpad:master

 

Simone Pelosi has proposed merging ~pelpsi/launchpad:send-bug-notifications-opsees-list-index-out-of-range into launchpad:master.

Commit message:
Fixed list index out of range
    
filters_by_person[x] set was replaced every iteration.
Now it's updated using the "update" set function.


Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pelpsi/launchpad/+git/launchpad/+merge/445114
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/launchpad:send-bug-notifications-opsees-list-index-out-of-range into launchpad:master.
diff --git a/lib/lp/bugs/model/bugnotification.py b/lib/lp/bugs/model/bugnotification.py
index bb51a63..7078cda 100644
--- a/lib/lp/bugs/model/bugnotification.py
+++ b/lib/lp/bugs/model/bugnotification.py
@@ -327,10 +327,12 @@ class BugNotificationSet:
             ] = filter_description
             filter_ids.append(filter_id)
 
-            filters_by_person[source_person_id] = {
-                (i, filter_id)
-                for i in source_person_id_map[source_person_id]["sources"]
-            }
+            filters_by_person[source_person_id].update(
+                {
+                    (i, filter_id)
+                    for i in source_person_id_map[source_person_id]["sources"]
+                }
+            )
 
         # Remaining notifications have no filters
         source_filter_ids = filters_by_person.keys()
@@ -392,7 +394,10 @@ class BugNotificationSet:
         for recipient_data in recipient_id_map.values():
             # Getting filtered sources
 
-            if recipient_data["filters"]:
+            if (
+                recipient_data["filters"]
+                and filters_by_person[recipient_data["principal"].id]
+            ):
                 filter_descriptions = [
                     description
                     for description in recipient_data["filters"].values()
diff --git a/lib/lp/bugs/scripts/tests/test_bugnotification.py b/lib/lp/bugs/scripts/tests/test_bugnotification.py
index b9b0a0a..a2efef1 100644
--- a/lib/lp/bugs/scripts/tests/test_bugnotification.py
+++ b/lib/lp/bugs/scripts/tests/test_bugnotification.py
@@ -54,6 +54,7 @@ from lp.bugs.scripts.bugnotification import (
     notification_comment_batches,
     process_deferred_notifications,
 )
+from lp.registry.enums import TeamMembershipPolicy
 from lp.registry.interfaces.person import IPersonSet
 from lp.registry.interfaces.product import IProductSet
 from lp.services.config import config
@@ -1533,6 +1534,7 @@ class TestSendBugNotifications(TestCaseWithFactory):
         subscription = bug.default_bugtask.target.addBugSubscription(
             team, team_owner
         )
+        print(subscription)
         # Take team subscription's filter
         subscription_filter = subscription.bug_filters.one()
         bug.default_bugtask.target.addBugSubscription(
@@ -1572,3 +1574,61 @@ class TestSendBugNotifications(TestCaseWithFactory):
         self.assertEqual(
             "team-participant", messages[1]["X-Launchpad-Message-For"]
         )
+
+    def test_team_subscription_with_multiple_filters(self):
+
+        team_owner = self.factory.makePerson(
+            name="team-owner-name", email="team-owner@xxxxxxxxxxxxx"
+        )
+
+        bug_watcher = self.factory.makePerson(
+            name="bug-watcher-name", email="bug-watcher@xxxxxxxxxxxxx"
+        )
+
+        team = self.factory.makeTeam(
+            name="team-name",
+            owner=team_owner,
+            members=[bug_watcher, team_owner],
+            membership_policy=TeamMembershipPolicy.RESTRICTED,
+        )
+
+        bug = self.factory.makeBug(owner=team_owner)
+
+        subscription = bug.default_bugtask.target.addSubscription(
+            team, team_owner
+        )
+
+        message = getUtility(IMessageSet).fromText(
+            "subject",
+            "a comment.",
+            team_owner,
+            datecreated=self.ten_minutes_ago,
+        )
+        recipients = bug.getBugNotificationRecipients()
+        notification = getUtility(IBugNotificationSet).addNotification(
+            bug=bug,
+            is_comment=True,
+            message=message,
+            recipients=recipients,
+            activity=None,
+        )
+
+        bug_filter = subscription.newBugFilter()
+        bug_filter.description = "New Filter"
+        BugNotificationFilter(
+            bug_notification=notification,
+            bug_subscription_filter=bug_filter,
+        )
+        BugSubscriptionFilterMute(
+            person=bug_watcher,
+            filter=bug_filter,
+        )
+        notification = self.notification_set.getNotificationsToSend()
+
+        pending_notification = get_email_notifications(notification)
+
+        _, _, messages = list(pending_notification)[0]
+
+        self.assertEqual(1, len(messages))
+        self.assertEqual("bug-watcher@xxxxxxxxxxxxx", messages[0]["To"])
+        self.assertEqual("team-name", messages[0]["X-Launchpad-Message-For"])