Skip to content

Commit 8090f8a

Browse files
committed
fix: update the write version and add fallback for old cache
1 parent 076acc8 commit 8090f8a

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

lms/djangoapps/course_blocks/transformers/library_content.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ContentLibraryTransformer(FilteringTransformerMixin, BlockStructureTransfo
5353
5454
Staff users are not to be exempted from item bank pathways.
5555
"""
56-
WRITE_VERSION = 1
56+
WRITE_VERSION = 2
5757
READ_VERSION = 1
5858

5959
@classmethod
@@ -104,7 +104,13 @@ def transform_block_filters(self, usage_info, block_structure):
104104
all_selected_children = set()
105105
for block_key in block_structure:
106106
# Check if this block was marked as an ItemBankMixin block during collect
107-
if not block_structure.get_transformer_block_field(block_key, self, 'is_item_bank_block'):
107+
is_item_bank = block_structure.get_transformer_block_field(block_key, self, 'is_item_bank_block')
108+
# Fallback for old cache that doesn't have the 'is_item_bank_block' field
109+
if is_item_bank is None:
110+
block_class = _get_block_class(block_key.block_type)
111+
is_item_bank = block_class and issubclass(block_class, ItemBankMixin)
112+
113+
if not is_item_bank:
108114
continue
109115
library_children = block_structure.get_children(block_key)
110116
if library_children:
@@ -259,10 +265,19 @@ def transform(self, usage_info, block_structure):
259265
to match the order of the selections made and stored in the XBlock 'selected' field.
260266
"""
261267
for block_key in block_structure:
262-
# Check if this block was marked as an ItemBankMixin block by ContentLibraryTransformer
263-
if not block_structure.get_transformer_block_field(
264-
block_key, ContentLibraryTransformer, 'is_item_bank_block'
265-
):
268+
# Try to read from cache (collected by ContentLibraryTransformer)
269+
is_item_bank = block_structure.get_transformer_block_field(
270+
block_key,
271+
ContentLibraryTransformer,
272+
'is_item_bank_block'
273+
)
274+
275+
# Fallback for old cache that doesn't have the 'is_item_bank_block' field
276+
if is_item_bank is None:
277+
block_class = _get_block_class(block_key.block_type)
278+
is_item_bank = block_class and issubclass(block_class, ItemBankMixin)
279+
280+
if not is_item_bank:
266281
continue
267282

268283
library_children = block_structure.get_children(block_key)

0 commit comments

Comments
 (0)