From 8c336ef998bee0caa214343e804742565a212355 Mon Sep 17 00:00:00 2001 From: cahrens Date: Tue, 16 Apr 2013 17:05:11 -0400 Subject: [PATCH] Don't try to export orphaned draft items. #278 --- .../contentstore/tests/test_contentstore.py | 4 ++++ .../xmodule/xmodule/modulestore/xml_exporter.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 4908b9e417..c5fb0a231b 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -386,6 +386,10 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): draft_store.clone_item(vertical.location, vertical.location) + # We had a bug where orphaned draft nodes caused export to fail. This is here to cover that case. + draft_store.clone_item(vertical.location, Location(['i4x', 'edX', 'full', + 'vertical', 'no_references', 'draft'])) + for child in vertical.get_children(): draft_store.clone_item(child.location, child.location) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_exporter.py b/common/lib/xmodule/xmodule/modulestore/xml_exporter.py index e03c61bb24..50bdf3a252 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_exporter.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_exporter.py @@ -50,12 +50,14 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d draft_course_dir = export_fs.makeopendir('drafts') for draft_vertical in draft_verticals: parent_locs = draft_modulestore.get_parent_locations(draft_vertical.location, course.location.course_id) - logging.debug('parent_locs = {0}'.format(parent_locs)) - draft_vertical.xml_attributes['parent_sequential_url'] = Location(parent_locs[0]).url() - sequential = modulestore.get_item(Location(parent_locs[0])) - index = sequential.children.index(draft_vertical.location.url()) - draft_vertical.xml_attributes['index_in_children_list'] = str(index) - draft_vertical.export_to_xml(draft_course_dir) + # Don't try to export orphaned items. + if len(parent_locs) > 0: + logging.debug('parent_locs = {0}'.format(parent_locs)) + draft_vertical.xml_attributes['parent_sequential_url'] = Location(parent_locs[0]).url() + sequential = modulestore.get_item(Location(parent_locs[0])) + index = sequential.children.index(draft_vertical.location.url()) + draft_vertical.xml_attributes['index_in_children_list'] = str(index) + draft_vertical.export_to_xml(draft_course_dir) def export_extra_content(export_fs, modulestore, course_location, category_type, dirname, file_suffix=''):