From eb6f6a57f08aa1fb3e74cbf380e06ff75baabdcd Mon Sep 17 00:00:00 2001 From: James Kachel Date: Fri, 2 Sep 2022 14:32:11 -0500 Subject: [PATCH] Wraps the check for a course page and certificate page in a try/except so it doesn't fail if there's no course page for the courserun enrollment --- courses/serializers.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/courses/serializers.py b/courses/serializers.py index 6806463e91..82a73e3c31 100644 --- a/courses/serializers.py +++ b/courses/serializers.py @@ -371,11 +371,14 @@ def get_certificate(self, enrollment): # No need to include a certificate if there is no corresponding wagtail page # to support the render - if ( - not enrollment - or not enrollment.run.course.page - or not enrollment.run.course.page.certificate_page - ): + try: + if ( + not enrollment + or not enrollment.run.course.page + or not enrollment.run.course.page.certificate_page + ): + return None + except models.Course.page.RelatedObjectDoesNotExist: return None # Using IDs because we don't need the actual record and this avoids redundant queries