Don't crash with committers without user profiles
authorMagnus Hagander <magnus@hagander.net>
Mon, 15 Feb 2016 09:38:31 +0000 (10:38 +0100)
committerMagnus Hagander <magnus@hagander.net>
Mon, 15 Feb 2016 09:38:31 +0000 (10:38 +0100)
Userprofiles aren't set for everbody, so catch a missing exception and
just ignore it since we know a user without a profile didn't specifically
ask to get notified (as that's stored in the profile).

pgcommitfest/commitfest/models.py

index 04d2fb4953a4de755db73afececcc87a93bf6c15..5ee0a5bd7b9bec79748ffc17b14dfdef04ff729f 100644 (file)
@@ -5,6 +5,8 @@ from datetime import datetime
 
 from util import DiffableModel
 
+from pgcommitfest.userprofile.models import UserProfile
+
 # We have few enough of these, and it's really the only thing we
 # need to extend from the user model, so just create a separate
 # class.
@@ -223,10 +225,17 @@ class PatchHistory(models.Model):
                recipients.extend(self.patch.subscribers.all())
 
                # Current or previous committer wants all notifications
-               if self.patch.committer and self.patch.committer.user.userprofile.notify_all_committer:
-                       recipients.append(self.patch.committer.user)
-               if prevcommitter and prevcommitter.user.userprofile.notify_all_committer:
-                       recipients.append(prevcommitter.user)
+               try:
+                       if self.patch.committer and self.patch.committer.user.userprofile.notify_all_committer:
+                               recipients.append(self.patch.committer.user)
+               except UserProfile.DoesNotExist:
+                       pass
+
+               try:
+                       if prevcommitter and prevcommitter.user.userprofile.notify_all_committer:
+                               recipients.append(prevcommitter.user)
+               except UserProfile.DoesNotExist:
+                       pass
 
                # Current or previous reviewers wants all notifications
                recipients.extend(self.patch.reviewers.filter(userprofile__notify_all_reviewer=True))