From 6642de5ce29c90293806370863c6e325bc5864a9 Mon Sep 17 00:00:00 2001 From: "Dave St.Germain" Date: Thu, 21 Nov 2019 09:51:24 -0500 Subject: [PATCH] Prevent 500 error when viewing malformed unit page PROD-1026 --- cms/djangoapps/contentstore/utils.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index baaf4ff535..1c09664955 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -547,19 +547,21 @@ def get_sibling_urls(subsection): last_block = block if not prev_loc: try: + # section.get_parent SHOULD return the course, but for some reason, it might not sections = section.get_parent().get_children() except AttributeError: log.error(u"Error retrieving URLs in subsection {subsection} included in section {section}".format( section=section.location, subsection=subsection.location )) - raise - - try: - prev_section = sections[sections.index(section) - 1] - prev_loc = prev_section.get_children()[-1].get_children()[-1].location - except IndexError: - pass + # This should not be a fatal error. The worst case is that the navigation on the unit page + # won't display a link to a previous unit. + else: + try: + prev_section = sections[sections.index(section) - 1] + prev_loc = prev_section.get_children()[-1].get_children()[-1].location + except IndexError: + pass if not next_loc: sections = section.get_parent().get_children() try: