Skip to content

Commit 599a8b4

Browse files
authored
fix: throws InvalidScopeError if the FieldData for the scope is None (#815)
1 parent 03251b2 commit 599a8b4

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Change history for XBlock
55
Unreleased
66
----------
77

8+
5.1.2 - 2025-02-07
9+
------------------
10+
11+
* throws InvalidScopeError if the scope is not defined
12+
813
5.1.0 - 2024-08-07
914
------------------
1015

xblock/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
XBlock Courseware Components
33
"""
44

5-
__version__ = '5.1.1'
5+
__version__ = '5.1.2'

xblock/field_data.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ def _field_data(self, block, name):
145145
"""Return the field data for the field `name` on the :class:`~xblock.core.XBlock` `block`"""
146146
scope = block.fields[name].scope
147147

148-
if scope not in self._scope_mappings:
148+
scope_mapping = self._scope_mappings.get(scope)
149+
150+
if scope_mapping is None:
149151
raise InvalidScopeError(scope)
150152

151-
return self._scope_mappings[scope]
153+
return scope_mapping
152154

153155
def get(self, block, name):
154156
return self._field_data(block, name).get(block, name)

xblock/test/test_field_data.py

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def setup_method(self):
4040
Scope.content: self.content,
4141
Scope.settings: self.settings
4242
})
43+
self.split_empty = SplitFieldData({
44+
Scope.content: self.content,
45+
Scope.settings: self.settings,
46+
Scope.user_state: None,
47+
})
4348
self.runtime = TestRuntime(services={'field-data': self.split})
4449
self.block = TestingBlock(
4550
runtime=self.runtime,
@@ -76,6 +81,10 @@ def test_invalid_scope(self):
7681
with pytest.raises(InvalidScopeError):
7782
self.split.get(self.block, 'user_state')
7883

84+
def test_empty_scope(self):
85+
with pytest.raises(InvalidScopeError):
86+
self.split_empty.get(self.block, 'user_state')
87+
7988
def test_default(self):
8089
self.split.default(self.block, 'content')
8190
self.content.default.assert_called_once_with(self.block, 'content')

0 commit comments

Comments
 (0)