Skip to content

Commit

Permalink
fix: throw exception if field is None on scope_mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Feb 4, 2025
1 parent e0df689 commit 5c96401
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions xblock/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
simple.
"""
import copy

from abc import ABCMeta, abstractmethod
from collections import defaultdict

Expand Down Expand Up @@ -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)

Check warning on line 153 in xblock/field_data.py

View check run for this annotation

Codecov / codecov/patch

xblock/field_data.py#L153

Added line #L153 was not covered by tests

return scope_mapping

def get(self, block, name):
return self._field_data(block, name).get(block, name)
Expand All @@ -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

Check warning on line 171 in xblock/field_data.py

View check run for this annotation

Codecov / codecov/patch

xblock/field_data.py#L170-L171

Added lines #L170 - L171 were not covered by tests

def delete(self, block, name):
self._field_data(block, name).delete(block, name)
Expand Down

0 comments on commit 5c96401

Please sign in to comment.