From 2ca9d4d07049f724b03a0d38c0bb7e65ea04c769 Mon Sep 17 00:00:00 2001 From: mushtaqali Date: Mon, 29 Jun 2015 23:43:29 +0500 Subject: [PATCH] Fix 'stuck in publish issue' when deleting an item after dicarding the changes --- .../xmodule/modulestore/split_mongo/split.py | 2 + .../tests/test_mixed_modulestore.py | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index 64ccfb824a..5ac0a50faf 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -2397,6 +2397,8 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): parent_block.edit_info.edited_by = user_id parent_block.edit_info.previous_version = parent_block.edit_info.update_version parent_block.edit_info.update_version = new_id + # remove the source_version reference + parent_block.edit_info.source_version = None self.decache_block(usage_locator.course_key, new_id, parent_block_key) self._remove_subtree(BlockKey.from_usage_key(usage_locator), new_blocks) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py index 69f5a433a5..4ed6aa7c00 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -592,6 +592,49 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): # Verify that changes are present self.assertTrue(self.store.has_changes(component)) + @ddt.data('draft', 'split') + def test_unit_stuck_in_published_mode_after_delete(self, default_ms): + """ + Test that a unit does not get stuck in published mode + after discarding a component changes and deleting a component + """ + self.initdb(default_ms) + + test_course = self.store.create_course('testx', 'GreekHero', 'test_run', self.user_id) + + # Create a dummy vertical & html component to test against + vertical = self.store.create_item( + self.user_id, + test_course.id, + 'vertical', + block_id='test_vertical' + ) + component = self.store.create_child( + self.user_id, + vertical.location, + 'html', + block_id='html_component' + ) + + # publish vertical changes + self.store.publish(vertical.location, self.user_id) + self.assertFalse(self._has_changes(vertical.location)) + + # Change a component, then check that there now are changes + component = self.store.get_item(component.location) + component.display_name = 'Changed Display Name' + self.store.update_item(component, self.user_id) + self.assertTrue(self._has_changes(vertical.location)) + + # Discard changes and verify that there are no changes + self.store.revert_to_published(vertical.location, self.user_id) + self.assertFalse(self._has_changes(vertical.location)) + + # Delete the component and verify that the unit has changes + self.store.delete_item(component.location, self.user_id) + vertical = self.store.get_item(vertical.location) + self.assertTrue(self._has_changes(vertical.location)) + def setup_has_changes(self, default_ms): """ Common set up for has_changes tests below.