diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6a5eff3a9..1f411a65d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ------------------ diff --git a/xblock/__init__.py b/xblock/__init__.py index bf676c4f5..1fa8a5fc6 100644 --- a/xblock/__init__.py +++ b/xblock/__init__.py @@ -2,4 +2,4 @@ XBlock Courseware Components """ -__version__ = '5.1.1' +__version__ = '5.1.2' diff --git a/xblock/field_data.py b/xblock/field_data.py index 7d3d8abbf..faa66e394 100644 --- a/xblock/field_data.py +++ b/xblock/field_data.py @@ -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) diff --git a/xblock/test/test_field_data.py b/xblock/test/test_field_data.py index ce568ba3e..eaf12281e 100644 --- a/xblock/test/test_field_data.py +++ b/xblock/test/test_field_data.py @@ -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, @@ -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')