Commit 3c042b52 by Calen Pennington

Clear out the cache xmodule_instance after an exception in XModule init

This guarantees that the ErrorModule will be created, instead of
potentially using a partially instatiated broken module. Fixes
[LMS-1532].
parent 8d62fa14
...@@ -119,7 +119,6 @@ class TestErrorModuleConstruction(unittest.TestCase): ...@@ -119,7 +119,6 @@ class TestErrorModuleConstruction(unittest.TestCase):
self.descriptor.xmodule_runtime.error_descriptor_class = ErrorDescriptor self.descriptor.xmodule_runtime.error_descriptor_class = ErrorDescriptor
self.descriptor.xmodule_runtime.xmodule_instance = None self.descriptor.xmodule_runtime.xmodule_instance = None
@unittest.expectedFailure
def test_broken_module(self): def test_broken_module(self):
""" """
Test that when an XModule throws an error during __init__, we Test that when an XModule throws an error during __init__, we
...@@ -136,7 +135,6 @@ class TestErrorModuleConstruction(unittest.TestCase): ...@@ -136,7 +135,6 @@ class TestErrorModuleConstruction(unittest.TestCase):
with self.assertRaises(TestException): with self.assertRaises(TestException):
module = self.descriptor._xmodule module = self.descriptor._xmodule
@unittest.expectedFailure
@patch.object(ErrorModule, '__init__', Mock(side_effect=TestException)) @patch.object(ErrorModule, '__init__', Mock(side_effect=TestException))
def test_broken_error_module(self): def test_broken_error_module(self):
""" """
......
...@@ -746,6 +746,10 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock): ...@@ -746,6 +746,10 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
) )
self.xmodule_runtime.xmodule_instance.save() self.xmodule_runtime.xmodule_instance.save()
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
# xmodule_instance is set by the XModule.__init__. If we had an error after that,
# we need to clean it out so that we can set up the ErrorModule instead
self.xmodule_runtime.xmodule_instance = None
if isinstance(self, self.xmodule_runtime.error_descriptor_class): if isinstance(self, self.xmodule_runtime.error_descriptor_class):
log.exception('Error creating an ErrorModule from an ErrorDescriptor') log.exception('Error creating an ErrorModule from an ErrorDescriptor')
raise raise
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment