Commit 0059f88d by Eric Fischer

Silence XML parse error in capa_module

TNL-5057 This un-actionable error is polluting the stream of devops pages, and
should be quieted. A longer term fix will be made in TNL-5245.
parent 477d6dd2
......@@ -220,9 +220,13 @@ class CapaDescriptor(CapaFields, RawDescriptor):
@property
def problem_types(self):
""" 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()
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):
"""
......@@ -263,9 +267,10 @@ class CapaDescriptor(CapaFields, RawDescriptor):
Returns whether the given view has support for the given functionality.
"""
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
for tag in self.problem_types
for tag in types
)
return False
......
......@@ -13,6 +13,7 @@ import textwrap
import unittest
import ddt
from lxml import etree
from mock import Mock, patch, DEFAULT
import webob
from webob.multidict import MultiDict
......@@ -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):
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