diff --git a/xblock/field_data.py b/xblock/field_data.py index 7d3d8abbf..44c40f736 100644 --- a/xblock/field_data.py +++ b/xblock/field_data.py @@ -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) 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')