From 79e96af197da51fafd394e5377093e379ea19f88 Mon Sep 17 00:00:00 2001 From: Dillon Dumesnil <ddumesnil@edx.org> Date: Wed, 19 Aug 2020 11:39:50 -0700 Subject: [PATCH] Disable updating Library Content children during import --- .../views/tests/test_import_export.py | 76 +++++++++---------- .../xmodule/modulestore/xml_importer.py | 32 ++++---- 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index 81ee02b1243..e8d451397a6 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -985,44 +985,44 @@ class TestCourseExportImport(LibraryTestCase): dest_child = self.store.get_item(dest_child_location) self.assertEqual(source_child.display_name, dest_child.display_name) - @ddt.data(True, False) - def test_library_content_on_course_export_import(self, publish_item): - """ - Verify that library contents in destination and source courses are same after importing - the source course into destination course. - """ - self._setup_source_course_with_library_content(publish=publish_item) - - # Create a course to import source course. - dest_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) - - # Export the source course. - export_course_to_xml( - self.store, - contentstore(), - self.source_course.location.course_key, - self.export_dir, - 'exported_source_course', - ) - - # Now, import it back to dest_course. - import_course_from_xml( - self.store, - self.user.id, - self.export_dir, - ['exported_source_course'], - static_content_store=contentstore(), - target_id=dest_course.location.course_key, - load_error_modules=False, - raise_on_failure=True, - create_if_not_present=True, - ) - - self.assert_problem_display_names( - self.source_course.location, - dest_course.location, - publish_item - ) + # @ddt.data(True, False) + # def test_library_content_on_course_export_import(self, publish_item): + # """ + # Verify that library contents in destination and source courses are same after importing + # the source course into destination course. + # """ + # self._setup_source_course_with_library_content(publish=publish_item) + + # # Create a course to import source course. + # dest_course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) + + # # Export the source course. + # export_course_to_xml( + # self.store, + # contentstore(), + # self.source_course.location.course_key, + # self.export_dir, + # 'exported_source_course', + # ) + + # # Now, import it back to dest_course. + # import_course_from_xml( + # self.store, + # self.user.id, + # self.export_dir, + # ['exported_source_course'], + # static_content_store=contentstore(), + # target_id=dest_course.location.course_key, + # load_error_modules=False, + # raise_on_failure=True, + # create_if_not_present=True, + # ) + + # self.assert_problem_display_names( + # self.source_course.location, + # dest_course.location, + # publish_item + # ) @ddt.ddt diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index c52ef40b066..ee45c4bcce9 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -822,20 +822,26 @@ def _update_and_import_module( # Get to the point where XML import is happening inside the # modulestore that is eventually going to store the data. # Ticket: https://openedx.atlassian.net/browse/PLAT-1046 - if block.location.block_type == 'library_content': - # if library exists, update source_library_version and children - # according to this existing library and library content block. - if store.get_library(block.source_library_key): - # Update library content block's children on draft branch - with store.branch_setting(branch_setting=ModuleStoreEnum.Branch.draft_preferred): - LibraryToolsService(store, user_id).update_children( - block, - version=block.source_library_version, - ) - # Publish it if importing the course for branch setting published_only. - if store.get_branch_setting() == ModuleStoreEnum.Branch.published_only: - store.publish(block.location, user_id) + ## Disabling library content children update during import as we saw it cause + ## an issue where the children were recalculated causing learner's to lose their + ## current state. + ## If this is brought back in, also uncomment the tests in + ## cms/djangoapps/contentstore/views/tests/test_import_export.py + # if block.location.block_type == 'library_content': + # # if library exists, update source_library_version and children + # # according to this existing library and library content block. + # if store.get_library(block.source_library_key): + # # Update library content block's children on draft branch + # with store.branch_setting(branch_setting=ModuleStoreEnum.Branch.draft_preferred): + # LibraryToolsService(store, user_id).update_children( + # block, + # version=block.source_library_version, + # ) + + # # Publish it if importing the course for branch setting published_only. + # if store.get_branch_setting() == ModuleStoreEnum.Branch.published_only: + # store.publish(block.location, user_id) return block -- GitLab