Commit 2e23a5f5 by Don Mitchell

Merge pull request #1615 from MITx/fix/cdodge/error-importing-metadata-with-empty-strings

make export a bit more resilient. If there's a piece of metadata that we...
parents 1b7863e7 9ba75980
...@@ -263,7 +263,33 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -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): ...@@ -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))
try:
xml_object.set(attr, val) 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
......
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