From 5c9640133f0cdf16630413a4c377e854fc1759e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Tue, 4 Feb 2025 13:04:17 -0300 Subject: [PATCH] fix: throw exception if field is None on scope_mappings --- xblock/field_data.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/xblock/field_data.py b/xblock/field_data.py index 1663f7b0a..ee0546c06 100644 --- a/xblock/field_data.py +++ b/xblock/field_data.py @@ -5,7 +5,6 @@ simple. """ import copy - from abc import ABCMeta, abstractmethod from collections import defaultdict @@ -148,7 +147,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) @@ -161,8 +165,10 @@ def set_many(self, block, update_dict): for key, value in update_dict.items(): update_dicts[self._field_data(block, key)][key] = value for field_data, new_update_dict in update_dicts.items(): - if field_data is not None: # Ignore fields from scopes that are not loaded + try: field_data.set_many(block, new_update_dict) + except InvalidScopeError: + pass # Ignore fields that are not in the scope_mappings def delete(self, block, name): self._field_data(block, name).delete(block, name)