Skip to content

Commit 8a3e135

Browse files
fix: remove all duplicate children refs when deleting/moving xblocks
1 parent 559a63b commit 8a3e135

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def _save_xblock(
373373
old_parent_location = store.get_parent_location(new_child)
374374
if old_parent_location:
375375
old_parent = store.get_item(old_parent_location)
376-
old_parent.children.remove(new_child)
376+
old_parent.children = [c for c in old_parent.children if c != new_child]
377377
old_parent = save_xblock_with_callback(old_parent, user)
378378
else:
379379
# the Studio UI currently doesn't present orphaned children, so assume this is an error

xmodule/modulestore/draft_and_published.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def update_item_parent(self, item_location, new_parent_location, old_parent_loca
163163

164164
# Remove item from the list of children of old parent.
165165
if source_item.location in old_parent_item.children:
166-
old_parent_item.children.remove(source_item.location)
166+
old_parent_item.children = [c for c in old_parent_item.children if c != source_item.location]
167167
self.update_item(old_parent_item, user_id) # pylint: disable=no-member
168168
log.info(
169169
'%s removed from %s children',

xmodule/modulestore/split_mongo/split.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ def delete_item(self, usage_locator, user_id, force=False): # lint-amnesty, pyl
25402540
parent_block_keys = self._get_parents_from_structure(block_key, original_structure)
25412541
for parent_block_key in parent_block_keys:
25422542
parent_block = new_blocks[parent_block_key]
2543-
parent_block.fields['children'].remove(block_key)
2543+
parent_block.fields['children'] = [c for c in parent_block.fields['children'] if c != block_key]
25442544
parent_block.edit_info.edited_on = datetime.datetime.now(UTC)
25452545
parent_block.edit_info.edited_by = user_id
25462546
parent_block.edit_info.previous_version = parent_block.edit_info.update_version

0 commit comments

Comments
 (0)