diff --git a/xmodule/mako_block.py b/xmodule/mako_block.py index 6e6a78910465..abf3a93f3858 100644 --- a/xmodule/mako_block.py +++ b/xmodule/mako_block.py @@ -17,15 +17,18 @@ def __init__(self, render_template, **kwargs): self.render_template = render_template - # Add the MakoService to the descriptor system. + # Add the MakoService to the runtime services. + # If it already exists, do not attempt to reinitialize it; otherwise, this could override the `namespace_prefix` + # of the `MakoService`, breaking template rendering in Studio. # # This is not needed by most XBlocks, because the MakoService is added to their runtimes. # However, there are a few cases where the MakoService is not added to the XBlock's # runtime. Specifically: # * in the Instructor Dashboard bulk emails tab, when rendering the HtmlBlock for its WYSIWYG editor. # * during testing, when fetching factory-created blocks. - from common.djangoapps.edxmako.services import MakoService - self._services['mako'] = MakoService() + if 'mako' not in self._services: + from common.djangoapps.edxmako.services import MakoService + self._services['mako'] = MakoService() class MakoTemplateBlockBase: