Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Change history for XBlock
Unreleased
----------

5.1.2 - 2025-02-07
------------------

* throws InvalidScopeError if the scope is not defined

5.1.0 - 2024-08-07
------------------

Expand Down
2 changes: 1 addition & 1 deletion xblock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
XBlock Courseware Components
"""

__version__ = '5.1.1'
__version__ = '5.1.2'
6 changes: 4 additions & 2 deletions xblock/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ def _field_data(self, block, name):
"""Return the field data for the field `name` on the :class:`~xblock.core.XBlock` `block`"""
scope = block.fields[name].scope

if scope not in self._scope_mappings:
scope_mapping = self._scope_mappings.get(scope)

if scope_mapping is None:
raise InvalidScopeError(scope)

return self._scope_mappings[scope]
return scope_mapping

def get(self, block, name):
return self._field_data(block, name).get(block, name)
Expand Down
9 changes: 9 additions & 0 deletions xblock/test/test_field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def setup_method(self):
Scope.content: self.content,
Scope.settings: self.settings
})
self.split_empty = SplitFieldData({
Scope.content: self.content,
Scope.settings: self.settings,
Scope.user_state: None,
})
self.runtime = TestRuntime(services={'field-data': self.split})
self.block = TestingBlock(
runtime=self.runtime,
Expand Down Expand Up @@ -76,6 +81,10 @@ def test_invalid_scope(self):
with pytest.raises(InvalidScopeError):
self.split.get(self.block, 'user_state')

def test_empty_scope(self):
with pytest.raises(InvalidScopeError):
self.split_empty.get(self.block, 'user_state')

def test_default(self):
self.split.default(self.block, 'content')
self.content.default.assert_called_once_with(self.block, 'content')
Expand Down