From dac1c5abe1193ce51297d6aa6db32742b2f6cedc Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Mon, 29 May 2023 14:47:21 -0700 Subject: [PATCH] refactor: we don't need _unwrapped_field_data any more --- lms/djangoapps/courseware/tests/test_block_render.py | 10 +++++----- xmodule/modulestore/mongo/base.py | 11 ++++++----- xmodule/x_module.py | 7 ------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_block_render.py b/lms/djangoapps/courseware/tests/test_block_render.py index 55896d4fa9..0504772aa5 100644 --- a/lms/djangoapps/courseware/tests/test_block_render.py +++ b/lms/djangoapps/courseware/tests/test_block_render.py @@ -487,11 +487,10 @@ class BlockRenderTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase): self.mock_user, request, block, field_data_cache, course.id, course=course ) - # check that _unwrapped_field_data is the same as the original + # check that block.runtime.service(block, 'field-data-unbound') is the same as the original # _field_data, but now _field_data as been reset. - # pylint: disable=protected-access - assert block._unwrapped_field_data is original_field_data # lint-amnesty, pylint: disable=no-member - assert block._unwrapped_field_data is not block._field_data # lint-amnesty, pylint: disable=no-member + assert block.runtime.service(block, 'field-data-unbound') is original_field_data + assert block.runtime.service(block, 'field-data-unbound') is not block._field_data # pylint: disable=protected-access, line-too-long # now bind this block to a few other students for user in [UserFactory(), UserFactory(), self.mock_user]: @@ -513,7 +512,8 @@ class BlockRenderTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase): # the OverrideFieldData should point to the date FieldData assert isinstance(block._field_data._authored_data._source.fallback, DateLookupFieldData) # lint-amnesty, pylint: disable=no-member, line-too-long - assert block._field_data._authored_data._source.fallback._defaults is block._unwrapped_field_data # lint-amnesty, pylint: disable=no-member, line-too-long + assert block._field_data._authored_data._source.fallback._defaults \ + is block.runtime.service(block, 'field-data-unbound') def test_hash_resource(self): """ diff --git a/xmodule/modulestore/mongo/base.py b/xmodule/modulestore/mongo/base.py index 9a04a8099d..469ef608a5 100644 --- a/xmodule/modulestore/mongo/base.py +++ b/xmodule/modulestore/mongo/base.py @@ -170,6 +170,12 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin): # li A system that has a cache of block json that it will use to load blocks from, with a backup of calling to the underlying modulestore for more data """ + + # This CachingDescriptorSystem runtime sets block._field_data on each block via construct_xblock_from_class(), + # rather than the newer approach of providing a "field-data" service via runtime.service(). As a result, during + # bind_for_student() we can't just set ._bound_field_data; we must overwrite block._field_data. + uses_deprecated_field_data = True + def __repr__(self): return "CachingDescriptorSystem{!r}".format(( self.modulestore, @@ -177,11 +183,6 @@ class CachingDescriptorSystem(MakoDescriptorSystem, EditInfoRuntimeMixin): # li [str(key) for key in self.module_data.keys()], self.default_class, )) - - # This CachingDescriptorSystem runtime sets block._field_data on each block via construct_xblock_from_class(), - # rather than the newer approach of providing a "field-data" service via runtime.service(). As a result, during - # bind_for_student() we can't just set ._bound_field_data; we must overwrite block._field_data. - uses_deprecated_field_data = True def __init__(self, modulestore, course_key, module_data, default_class, **kwargs): """ diff --git a/xmodule/x_module.py b/xmodule/x_module.py index 74fa31918e..da0eed90e9 100644 --- a/xmodule/x_module.py +++ b/xmodule/x_module.py @@ -429,13 +429,6 @@ class XModuleMixin(XModuleFields, XBlock): self.save() return self._field_data._kvs # pylint: disable=protected-access - def _unwrapped_field_data(self): - """ - This property gets the field-data service before we wrap it in user-specifc wrappers during bind_for_student, - e.g. the LmsFieldData or OverrideFieldData classes. - """ - return self.runtime.service(self, 'field-data-unbound') - def add_aside(self, aside): """ save connected asides