Skip to content

Commit ab63faf

Browse files
committed
fix: throws InvalidScopeError if the FieldData for the scope is None
1 parent 03251b2 commit ab63faf

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

xblock/field_data.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ def _field_data(self, block, name):
148148
if scope not in self._scope_mappings:
149149
raise InvalidScopeError(scope)
150150

151-
return self._scope_mappings[scope]
151+
scope_mapping = self._scope_mappings[scope]
152+
153+
if scope_mapping is None:
154+
raise InvalidScopeError(scope)
155+
156+
return scope_mapping
152157

153158
def get(self, block, name):
154159
return self._field_data(block, name).get(block, name)

xblock/test/test_field_data.py

Lines changed: 9 additions & 0 deletions
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)