Skip to content

Commit

Permalink
refactor: we don't need _unwrapped_field_data any more
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed May 29, 2023
1 parent 6dd9d2e commit dac1c5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
10 changes: 5 additions & 5 deletions lms/djangoapps/courseware/tests/test_block_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,10 @@ def create_aside(item, block_type):
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]:
Expand All @@ -513,7 +512,8 @@ def create_aside(item, block_type):

# 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):
"""
Expand Down
11 changes: 6 additions & 5 deletions xmodule/modulestore/mongo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,19 @@ 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,
str(self.course_id),
[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):
"""
Expand Down
7 changes: 0 additions & 7 deletions xmodule/x_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,6 @@ def xblock_kvs(self):
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
Expand Down

0 comments on commit dac1c5a

Please sign in to comment.