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].
This commit is contained in:
@@ -119,7 +119,6 @@ class TestErrorModuleConstruction(unittest.TestCase):
|
||||
self.descriptor.xmodule_runtime.error_descriptor_class = ErrorDescriptor
|
||||
self.descriptor.xmodule_runtime.xmodule_instance = None
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_broken_module(self):
|
||||
"""
|
||||
Test that when an XModule throws an error during __init__, we
|
||||
@@ -136,7 +135,6 @@ class TestErrorModuleConstruction(unittest.TestCase):
|
||||
with self.assertRaises(TestException):
|
||||
module = self.descriptor._xmodule
|
||||
|
||||
@unittest.expectedFailure
|
||||
@patch.object(ErrorModule, '__init__', Mock(side_effect=TestException))
|
||||
def test_broken_error_module(self):
|
||||
"""
|
||||
|
||||
@@ -746,6 +746,10 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
|
||||
)
|
||||
self.xmodule_runtime.xmodule_instance.save()
|
||||
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):
|
||||
log.exception('Error creating an ErrorModule from an ErrorDescriptor')
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user