From 0059f88d2aef6876f79733e4634c6fd00acb6669 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 24 Aug 2016 10:39:21 -0400 Subject: [PATCH] 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. --- common/lib/xmodule/xmodule/capa_module.py | 13 +++++++++---- .../xmodule/xmodule/tests/test_capa_module.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index 5fc906e9eb..c91cdb3e6f 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -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 diff --git a/common/lib/xmodule/xmodule/tests/test_capa_module.py b/common/lib/xmodule/xmodule/tests/test_capa_module.py index 45546ddec9..d886869838 100644 --- a/common/lib/xmodule/xmodule/tests/test_capa_module.py +++ b/common/lib/xmodule/xmodule/tests/test_capa_module.py @@ -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(""" + +