From 44074f30a2fc796a47a71e3593b615c681314af0 Mon Sep 17 00:00:00 2001 From: Sanford Student Date: Fri, 2 Dec 2016 13:24:54 -0500 Subject: [PATCH] move course version repopulation to runtime layer for TNL-6065 --- common/lib/xmodule/xmodule/modulestore/mongo/base.py | 2 +- .../split_mongo/caching_descriptor_system.py | 7 +++++++ .../xmodule/xmodule/modulestore/split_mongo/split.py | 10 +--------- .../modulestore/tests/test_mixed_modulestore.py | 4 ++++ lms/djangoapps/grades/tests/test_transformer.py | 4 ++++ 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py index 0d87f9a889..bd631c4724 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py @@ -955,7 +955,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo item = system.load_item(location, for_parent=for_parent) - # TODO Once PLAT-1055 is implemented, we can remove the following line + # TODO Once TNL-5092 is implemented, we can remove the following line # of code. Until then, set the course_version field on the block to be # consistent with the Split modulestore. Since Mongo modulestore doesn't # maintain course versions set it to None. diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/caching_descriptor_system.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/caching_descriptor_system.py index 202d32ef1a..2e5d3f7cfe 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/caching_descriptor_system.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/caching_descriptor_system.py @@ -131,6 +131,13 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin): class_ = self.load_block_type(block_data.block_type) block = self.xblock_from_json(class_, course_key, block_key, block_data, course_entry_override, **kwargs) + + # TODO Once TNL-5092 is implemented, we can expose the course version + # information within the key identifier of the block. Until then, set + # the course_version as a field on the returned block so higher layers + # can use it when needed. + block.course_version = version_guid + self.modulestore.cache_block(course_key, version_guid, block_key, block) return block diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index 8d4549a6d1..17d2f96afc 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -779,15 +779,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): self._add_cache(course_entry.structure['_id'], runtime) self.cache_items(runtime, block_keys, course_entry.course_key, depth, lazy) - blocks = [runtime.load_item(block_key, course_entry, **kwargs) for block_key in block_keys] - - # TODO Once PLAT-1055 is implemented, we can expose the course version - # information within the key identifier of the block. Until then, set - # the course_version as a field on each returned block so higher layers - # can use it when needed. - for block in blocks: - block.course_version = course_entry.course_key.version_guid - return blocks + return [runtime.load_item(block_key, course_entry, **kwargs) for block_key in block_keys] def _get_cache(self, course_version_guid): """ 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 6c48f8c77d..a117c2498d 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -454,6 +454,10 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): self.assertEquals(len(blocks), 7) for block in blocks: self.assertEquals(block.course_version, course_version) + # ensure that when the block is retrieved from the runtime cache, + # the course version is still present + cached_block = course.runtime.load_item(block.location) + self.assertEqual(cached_block.course_version, block.course_version) @ddt.data((ModuleStoreEnum.Type.split, 2, False), (ModuleStoreEnum.Type.mongo, 3, True)) @ddt.unpack diff --git a/lms/djangoapps/grades/tests/test_transformer.py b/lms/djangoapps/grades/tests/test_transformer.py index ee939aa5af..8daa5ecc27 100644 --- a/lms/djangoapps/grades/tests/test_transformer.py +++ b/lms/djangoapps/grades/tests/test_transformer.py @@ -352,6 +352,10 @@ class GradesTransformerTestCase(CourseStructureTestCase): blocks = self.build_course_with_problems() block_structure = get_course_blocks(self.student, blocks[u'course'].location, self.transformers) self.assertIsNotNone(block_structure.get_xblock_field(blocks[u'course'].location, u'course_version')) + self.assertEqual( + block_structure.get_xblock_field(blocks[u'problem'].location, u'course_version'), + block_structure.get_xblock_field(blocks[u'course'].location, u'course_version') + ) def test_grading_policy_collected(self): # the calculated hash of the original and updated grading policies of the test course