Commit 2dc4f5d6 by Eric Fischer Committed by GitHub

Merge pull request #13303 from edx/efischer/tnl_5057

TNL 5057 Silence XML parse error in capa_module
parents bf421108 0059f88d
...@@ -220,9 +220,13 @@ class CapaDescriptor(CapaFields, RawDescriptor): ...@@ -220,9 +220,13 @@ class CapaDescriptor(CapaFields, RawDescriptor):
@property @property
def problem_types(self): def problem_types(self):
""" Low-level problem type introspection for content libraries filtering by problem type """ """ Low-level problem type introspection for content libraries filtering by problem type """
tree = etree.XML(self.data) try:
tree = etree.XML(self.data)
except etree.XMLSyntaxError:
log.error('Error parsing problem types from xml for capa module {}'.format(self.display_name))
return None # short-term fix to prevent errors (TNL-5057). Will be more properly addressed in TNL-4525.
registered_tags = responsetypes.registry.registered_tags() registered_tags = responsetypes.registry.registered_tags()
return set([node.tag for node in tree.iter() if node.tag in registered_tags]) return {node.tag for node in tree.iter() if node.tag in registered_tags}
def index_dictionary(self): def index_dictionary(self):
""" """
...@@ -263,9 +267,10 @@ class CapaDescriptor(CapaFields, RawDescriptor): ...@@ -263,9 +267,10 @@ class CapaDescriptor(CapaFields, RawDescriptor):
Returns whether the given view has support for the given functionality. Returns whether the given view has support for the given functionality.
""" """
if functionality == "multi_device": if functionality == "multi_device":
return all( types = self.problem_types # Avoid calculating this property twice
return types is not None and all(
responsetypes.registry.get_class_for_tag(tag).multi_device_support responsetypes.registry.get_class_for_tag(tag).multi_device_support
for tag in self.problem_types for tag in types
) )
return False return False
......
...@@ -13,6 +13,7 @@ import textwrap ...@@ -13,6 +13,7 @@ import textwrap
import unittest import unittest
import ddt import ddt
from lxml import etree
from mock import Mock, patch, DEFAULT from mock import Mock, patch, DEFAULT
import webob import webob
from webob.multidict import MultiDict from webob.multidict import MultiDict
...@@ -2517,6 +2518,21 @@ class CapaDescriptorTest(unittest.TestCase): ...@@ -2517,6 +2518,21 @@ class CapaDescriptorTest(unittest.TestCase):
} }
) )
def test_invalid_xml_handling(self):
"""
Tests to confirm that invalid XML does not throw a wake-up-ops level error.
See TNL-5057 for quick fix, TNL-5245 for full resolution.
"""
sample_invalid_xml = textwrap.dedent("""
<problem>
</proble-oh no my finger broke and I can't close the problem tag properly...
""")
descriptor = self._create_descriptor(sample_invalid_xml, name="Invalid XML")
try:
descriptor.has_support(None, "multi_device")
except etree.XMLSyntaxError:
self.fail("Exception raised during XML parsing, this method should be resilient to such errors")
class ComplexEncoderTest(unittest.TestCase): class ComplexEncoderTest(unittest.TestCase):
def test_default(self): def test_default(self):
......
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