refactor: we don't need _unwrapped_field_data any more

This commit is contained in:
Braden MacDonald
2023-05-29 14:47:21 -07:00
parent 6dd9d2e068
commit dac1c5abe1
3 changed files with 11 additions and 17 deletions

View File

@@ -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):
"""

View File

@@ -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):
"""

View File

@@ -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