make export a bit more resilient. If there's a piece of metadata that we can't serialize - i.e. someone wrote a new bool attribute and didn't put it in the type mapping table - then we log the exception and continue.
This commit is contained in:
@@ -263,7 +263,33 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
|
|||||||
# note, we know the link it should be because that's what in the 'full' course in the test data
|
# note, we know the link it should be because that's what in the 'full' course in the test data
|
||||||
self.assertContains(resp, '/c4x/edX/full/asset/handouts_schematic_tutorial.pdf')
|
self.assertContains(resp, '/c4x/edX/full/asset/handouts_schematic_tutorial.pdf')
|
||||||
|
|
||||||
|
def test_export_course_with_unknown_metadata(self):
|
||||||
|
ms = modulestore('direct')
|
||||||
|
cs = contentstore()
|
||||||
|
|
||||||
|
import_from_xml(ms, 'common/test/data/', ['full'])
|
||||||
|
location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012')
|
||||||
|
|
||||||
|
root_dir = path(mkdtemp_clean())
|
||||||
|
|
||||||
|
course = ms.get_item(location)
|
||||||
|
|
||||||
|
# add a bool piece of unknown metadata so we can verify we don't throw an exception
|
||||||
|
course.metadata['new_metadata'] = True
|
||||||
|
|
||||||
|
ms.update_metadata(location, course.metadata)
|
||||||
|
|
||||||
|
print 'Exporting to tempdir = {0}'.format(root_dir)
|
||||||
|
|
||||||
|
# export out to a tempdir
|
||||||
|
bExported = False
|
||||||
|
try:
|
||||||
|
export_to_xml(ms, cs, location, root_dir, 'test_export')
|
||||||
|
bExported = True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.assertTrue(bExported)
|
||||||
|
|
||||||
class ContentStoreTest(ModuleStoreTestCase):
|
class ContentStoreTest(ModuleStoreTestCase):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -379,7 +379,11 @@ class XmlDescriptor(XModuleDescriptor):
|
|||||||
if attr not in self.metadata_to_strip and attr not in self.metadata_to_export_to_policy:
|
if attr not in self.metadata_to_strip and attr not in self.metadata_to_export_to_policy:
|
||||||
val = val_for_xml(attr)
|
val = val_for_xml(attr)
|
||||||
#logging.debug('location.category = {0}, attr = {1}'.format(self.location.category, attr))
|
#logging.debug('location.category = {0}, attr = {1}'.format(self.location.category, attr))
|
||||||
xml_object.set(attr, val)
|
try:
|
||||||
|
xml_object.set(attr, val)
|
||||||
|
except Exception, e:
|
||||||
|
logging.exception('Failed to serialize metadata attribute {0} with value {1}. This could mean data loss!!! Exception: {2}'.format(attr, val, e))
|
||||||
|
pass
|
||||||
|
|
||||||
if self.export_to_file():
|
if self.export_to_file():
|
||||||
# Write the definition to a file
|
# Write the definition to a file
|
||||||
|
|||||||
Reference in New Issue
Block a user