From 4e97104a3a6b9ff708d2ffbf11019d7889facffa Mon Sep 17 00:00:00 2001 From: "kshitij.sobti" Date: Tue, 17 Dec 2024 14:41:35 +0530 Subject: [PATCH 1/3] fix: use a single 'provider_type' key for storing discussion provider type in course Both 'provider' and 'provider_type' have been used for storing the discussion provider type in course 'discussions_settings' field, there are some places in the code checking for 'provider' and others checking for 'provider_type', in some cases this can cause a bug where it doesn't detect the correct provider which causes discussion settings not being copied correctly when a course is cloned. This change prioritises the `provider_type` setting over `provider` and reads `provider` only as a fallback. The `provider` setting is now made read-only just for backwards-compatibility, to avoid confusion. --- cms/djangoapps/contentstore/tasks.py | 2 +- openedx/core/djangoapps/discussions/tasks.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index 9a0b04d24377..4afd1cdcd51e 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -474,11 +474,11 @@ def sync_discussion_settings(course_key, user): if ( ENABLE_NEW_STRUCTURE_DISCUSSIONS.is_enabled() and not course.discussions_settings['provider_type'] == Provider.OPEN_EDX + and not course.discussions_settings['provider'] == Provider.OPEN_EDX ): LOGGER.info(f"New structure is enabled, also updating {course_key} to use new provider") course.discussions_settings['enable_graded_units'] = False course.discussions_settings['unit_level_visibility'] = True - course.discussions_settings['provider'] = Provider.OPEN_EDX course.discussions_settings['provider_type'] = Provider.OPEN_EDX modulestore().update_item(course, user.id) diff --git a/openedx/core/djangoapps/discussions/tasks.py b/openedx/core/djangoapps/discussions/tasks.py index 50a46065fede..a60b58bae336 100644 --- a/openedx/core/djangoapps/discussions/tasks.py +++ b/openedx/core/djangoapps/discussions/tasks.py @@ -201,7 +201,10 @@ def update_unit_discussion_state_from_discussion_blocks( """ store = modulestore() course = store.get_course(course_key) - provider = course.discussions_settings.get('provider', None) + provider = course.discussions_settings.get( + 'provider_type', + course.discussions_settings.get('provider', None), + ) # Only migrate to the new discussion provider if the current provider is the legacy provider. log.info(f"Current provider for {course_key} is {provider}") if provider is not None and provider != Provider.LEGACY and not force: From 3473d54c0dd34065337324fe55490edaf55c0903 Mon Sep 17 00:00:00 2001 From: Kshitij Sobti Date: Thu, 26 Jun 2025 15:57:41 +0530 Subject: [PATCH 2/3] fixup! fix: use a single 'provider_type' key for storing discussion provider type in course --- cms/djangoapps/contentstore/tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index 4afd1cdcd51e..fe8597db733f 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -473,8 +473,8 @@ def sync_discussion_settings(course_key, user): if ( ENABLE_NEW_STRUCTURE_DISCUSSIONS.is_enabled() - and not course.discussions_settings['provider_type'] == Provider.OPEN_EDX - and not course.discussions_settings['provider'] == Provider.OPEN_EDX + and not course.discussions_settings.get('provider_type', None) == Provider.OPEN_EDX + and not course.discussions_settings.get('provider', None) == Provider.OPEN_EDX ): LOGGER.info(f"New structure is enabled, also updating {course_key} to use new provider") course.discussions_settings['enable_graded_units'] = False From 0fe7a959b92360d70dff0dff04bbefecfebb969f Mon Sep 17 00:00:00 2001 From: Kshitij Sobti Date: Wed, 2 Jul 2025 22:34:17 +0530 Subject: [PATCH 3/3] fixup! fixup! fix: use a single 'provider_type' key for storing discussion provider type in course --- openedx/core/djangoapps/discussions/tasks.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openedx/core/djangoapps/discussions/tasks.py b/openedx/core/djangoapps/discussions/tasks.py index a60b58bae336..9fece99f03d5 100644 --- a/openedx/core/djangoapps/discussions/tasks.py +++ b/openedx/core/djangoapps/discussions/tasks.py @@ -201,6 +201,10 @@ def update_unit_discussion_state_from_discussion_blocks( """ store = modulestore() course = store.get_course(course_key) + # The provider information has been written to both `provider_type` and `provider`. + # Both of these serve the same purpose and this is an accident of early development. + # The `provider_type` key is now treated as read-only to allow existing values + # to be respected while moving to the `provider` key in the future. provider = course.discussions_settings.get( 'provider_type', course.discussions_settings.get('provider', None),