Skip to content

Commit 3d50dd8

Browse files
authored
Merge pull request #35259 from raccoongang/max/backport-error-page-render-recurse
[Backport] fix: Prevent error page recursion (#35209)
2 parents d5c84e9 + fa97f13 commit 3d50dd8

File tree

1 file changed

+21
-2
lines changed
  • lms/djangoapps/static_template_view

1 file changed

+21
-2
lines changed

lms/djangoapps/static_template_view/views.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# List of valid templates is explicitly managed for (short-term)
66
# security reasons.
77

8-
8+
import logging
99
import mimetypes
1010

1111
from django.conf import settings
@@ -23,6 +23,8 @@
2323
from common.djangoapps.util.views import fix_crum_request
2424
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
2525

26+
log = logging.getLogger(__name__)
27+
2628
valid_templates = []
2729

2830
if settings.STATIC_GRAB:
@@ -122,4 +124,21 @@ def render_429(request, exception=None): # lint-amnesty, pylint: disable=unused
122124

123125
@fix_crum_request
124126
def render_500(request):
125-
return HttpResponseServerError(render_to_string('static_templates/server-error.html', {}, request=request))
127+
"""
128+
Render the generic error page when we have an uncaught error.
129+
"""
130+
try:
131+
return HttpResponseServerError(render_to_string('static_templates/server-error.html', {}, request=request))
132+
except BaseException as e:
133+
# If we can't render the error page, ensure we don't raise another
134+
# exception -- because if we do, we'll probably just end up back
135+
# at the same rendering error.
136+
#
137+
# This is an attempt at working around the recursive error handling issues
138+
# observed in <https://github.com/openedx/edx-platform/issues/35151>, which
139+
# were triggered by Mako and translation errors.
140+
141+
log.error("Encountered error while rendering error page.", exc_info=True)
142+
# This message is intentionally hardcoded and does not involve
143+
# any translation, templating, etc. Do not translate.
144+
return HttpResponseServerError("Encountered error while rendering error page.")

0 commit comments

Comments
 (0)