From 84ecd9f035239a984450c85c1162ba5f17ecfe4e Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Mon, 7 Jul 2025 15:41:37 +0500 Subject: [PATCH] fix: optimizer error due to duplicate ids In this commit, fix optimizer error due to duplicate ids at sections and subsections level --- .../contentstore/core/course_optimizer_provider.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/core/course_optimizer_provider.py b/cms/djangoapps/contentstore/core/course_optimizer_provider.py index 8d40b958f0..7b44e05a87 100644 --- a/cms/djangoapps/contentstore/core/course_optimizer_provider.py +++ b/cms/djangoapps/contentstore/core/course_optimizer_provider.py @@ -251,7 +251,7 @@ CATEGORY_TO_LEVEL_MAP = { } -def _create_dto_recursive(xblock_node, xblock_dictionary): +def _create_dto_recursive(xblock_node, xblock_dictionary, parent_id=None): """ Recursively build the Data Transfer Object by using the structure from the node tree and data from the dictionary. @@ -264,7 +264,7 @@ def _create_dto_recursive(xblock_node, xblock_dictionary): xblock_children = [] for xblock_id, node in xblock_node.items(): - child_blocks = _create_dto_recursive(node, xblock_dictionary) + child_blocks = _create_dto_recursive(node, xblock_dictionary, parent_id=xblock_id) xblock_data = xblock_dictionary.get(xblock_id, {}) xblock_entry = { @@ -281,6 +281,13 @@ def _create_dto_recursive(xblock_node, xblock_dictionary): }) else: # Non-leaf node category = xblock_data.get('category', None) + # If parent and child has same IDs and level is 'sections', change it to 'subsections' + # And if parent and child has same IDs and level is 'subsections', change it to 'units' + if xblock_id == parent_id: + if category == "chapter": + category = "sequential" + elif category == "sequential": + category = "vertical" level = CATEGORY_TO_LEVEL_MAP.get(category, None) xblock_entry.update(child_blocks)