From 4988c42bcc50c93730f4693a85cbce41ebf77a58 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Mon, 15 Feb 2016 10:38:31 +0100 Subject: Don't crash with committers without user profiles 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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index 04d2fb4..5ee0a5b 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -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)) -- cgit v1.2.3