Skip to content

Commit

Permalink
fix: always define a student_data_store to prevent errors on XBlock load
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Feb 7, 2025
1 parent 02d2d34 commit 2d547e4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions openedx/core/djangoapps/xblock/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.exceptions import NoSuchServiceError
from xblock.field_data import FieldData, SplitFieldData
from xblock.field_data import DictFieldData, FieldData, SplitFieldData
from xblock.fields import Scope, ScopeIds
from xblock.runtime import IdReader, KvsFieldData, MemoryIdManager, Runtime

Expand Down Expand Up @@ -351,8 +351,10 @@ def _init_field_data_for_block(self, block: XBlock) -> FieldData:
Initialize the FieldData implementation for the specified XBlock
"""
if self.user is None:
# No user is specified, so we want to throw an error if anything attempts to read/write user-specific fields
student_data_store = None
# No user is specified, so we want to ignore any user-specific data. We cannot throw an
# error here because the XBlock loading process will write to the user_state if we have
# mutable fields.
student_data_store = DictFieldData({})
elif self.user.is_anonymous:
# This is an anonymous (non-registered) user:
assert isinstance(self.user_id, str) and self.user_id.startswith("anon")
Expand Down

0 comments on commit 2d547e4

Please sign in to comment.