From e15fcfab0a127a50c13df4367189051a9a2c1b0c Mon Sep 17 00:00:00 2001 From: Nate Vogel Date: Wed, 7 Feb 2024 21:54:23 -0500 Subject: [PATCH] silently swallow a couple errors that happen when People get incorrectly scraped. There's nothing to show, so lets show the user nothing instead of crashing the site. --- councilmatic_core/models.py | 9 ++++++++- councilmatic_core/views.py | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/councilmatic_core/models.py b/councilmatic_core/models.py index 4160b9f..d68bea5 100644 --- a/councilmatic_core/models.py +++ b/councilmatic_core/models.py @@ -228,6 +228,10 @@ def chairs(self): .select_related("person__councilmatic_person") ) for chair in chairs: + if chair.person is None: + # Silently continue if a None person was added in scraping, + # instead of crashing the site. + continue chair.person = chair.person.councilmatic_person return chairs else: @@ -305,7 +309,10 @@ def current_member(self): .select_related("person__councilmatic_person") .first() ) - if membership: + if membership and membership.person: + # Added `and membership.person` to silently + # handle the situation where a None membership gets added. + # And return nothing, instead of crashing the app. membership.person = membership.person.councilmatic_person return membership diff --git a/councilmatic_core/views.py b/councilmatic_core/views.py index 8a50b73..fd611b8 100644 --- a/councilmatic_core/views.py +++ b/councilmatic_core/views.py @@ -320,7 +320,6 @@ def get_context_data(self, **kwargs): for ces in user.committeeeventsubscriptions.all(): if committee == ces.committee: context["user_subscribed_events"] = True - return context