Skip to content

Commit

Permalink
fix: throws InvalidScopeError if the FieldData for the scope is None
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Feb 5, 2025
1 parent 03251b2 commit ab63faf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion xblock/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ def _field_data(self, block, name):
if scope not in self._scope_mappings:
raise InvalidScopeError(scope)

return self._scope_mappings[scope]
scope_mapping = self._scope_mappings[scope]

if scope_mapping is None:
raise InvalidScopeError(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

0 comments on commit ab63faf

Please sign in to comment.