From 25230b81d83ca9ddf92ebf870cb271a78c6d7334 Mon Sep 17 00:00:00 2001 From: Abdul-Muqadim-Arbisoft <139064778+Abdul-Muqadim-Arbisoft@users.noreply.github.com> Date: Wed, 8 Oct 2025 15:26:00 +0500 Subject: [PATCH 1/2] fix: prevent None entrance_exam_minimum_score_pct from breaking CourseOverview sync (#37339) * fix: prevent None entrance_exam_minimum_score_pct from breaking CourseOverview sync When entrance exams are disabled in Studio, the field `entrance_exam_minimum_score_pct` was set to `None`. This caused silent failures when saving `CourseOverview` because the database column requires a float (NOT NULL). This patch ensures that: - CourseOverview sanitizes None values by falling back to `settings.ENTRANCE_EXAM_MIN_SCORE_PCT` (default=50). - Studio avoids writing `None` and instead applies the configured default. Impact: - Prevents IntegrityErrors and silent failures when updating course settings. - Restores proper syncing between modulestore (Mongo) and CourseOverview (MySQL). - Fixes reported issues such as display name changes not persisting and course start dates not syncing. Closes: https://github.com/openedx/edx-platform/issues/37319# * refactor: clean up entrance_exam_minimum_score_pct handling - Consolidate logic to avoid repeated assignments - Centralize None fallback and int/float normalization - Improve readability with inline comment and consistency with Open edX style * test: update entrance exam deletion test to expect default min score - Adjusted `test_entrance_exam_created_updated_and_deleted_successfully` to check for `settings.ENTRANCE_EXAM_MIN_SCORE_PCT` instead of `None` after exam deletion - Added handling for both int and float defaults (`/100` for integer case) --- .../contentstore/tests/test_course_settings.py | 6 +++++- .../contentstore/views/entrance_exam.py | 2 +- .../content/course_overviews/models.py | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index 08d858c55062..4e79ba70993a 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -501,7 +501,11 @@ def test_entrance_exam_created_updated_and_deleted_successfully(self): course = modulestore().get_course(self.course.id) self.assertEqual(response.status_code, 200) self.assertFalse(course.entrance_exam_enabled) - self.assertEqual(course.entrance_exam_minimum_score_pct, None) + entrance_exam_minimum_score_pct = float(settings.ENTRANCE_EXAM_MIN_SCORE_PCT) + if entrance_exam_minimum_score_pct.is_integer(): + entrance_exam_minimum_score_pct = entrance_exam_minimum_score_pct / 100 + + self.assertEqual(course.entrance_exam_minimum_score_pct, entrance_exam_minimum_score_pct) self.assertFalse(milestones_helpers.any_unfulfilled_milestones(self.course.id, self.user.id), msg='The entrance exam should not be required anymore') diff --git a/cms/djangoapps/contentstore/views/entrance_exam.py b/cms/djangoapps/contentstore/views/entrance_exam.py index bbefb0e9e876..5d914366bd9e 100644 --- a/cms/djangoapps/contentstore/views/entrance_exam.py +++ b/cms/djangoapps/contentstore/views/entrance_exam.py @@ -224,7 +224,7 @@ def _delete_entrance_exam(request, course_key): if course.entrance_exam_id: metadata = { 'entrance_exam_enabled': False, - 'entrance_exam_minimum_score_pct': None, + 'entrance_exam_minimum_score_pct': _get_default_entrance_exam_minimum_pct(), 'entrance_exam_id': None, } CourseMetadata.update_from_dict(metadata, course, request.user) diff --git a/openedx/core/djangoapps/content/course_overviews/models.py b/openedx/core/djangoapps/content/course_overviews/models.py index 8ac975545e54..6389350d6005 100644 --- a/openedx/core/djangoapps/content/course_overviews/models.py +++ b/openedx/core/djangoapps/content/course_overviews/models.py @@ -266,10 +266,20 @@ def _create_or_update(cls, course): # lint-amnesty, pylint: disable=too-many-st course_overview.entrance_exam_id = course.entrance_exam_id or '' # Despite it being a float, the course object defaults to an int. So we will detect that case and update # it to be a float like everything else. - if isinstance(course.entrance_exam_minimum_score_pct, int): - course_overview.entrance_exam_minimum_score_pct = course.entrance_exam_minimum_score_pct / 100 - elif course.entrance_exam_minimum_score_pct is not None: - course_overview.entrance_exam_minimum_score_pct = course.entrance_exam_minimum_score_pct + # Extra handling: entrance_exam_minimum_score_pct can be None (e.g. when exams are disabled in Studio), + # so we fall back to settings.ENTRANCE_EXAM_MIN_SCORE_PCT to prevent CourseOverview save failures. + if course.entrance_exam_minimum_score_pct is None: + entrance_exam_minimum_score_pct = float(settings.ENTRANCE_EXAM_MIN_SCORE_PCT) + else: + entrance_exam_minimum_score_pct = course.entrance_exam_minimum_score_pct + + if ( + isinstance(entrance_exam_minimum_score_pct, int) + or (isinstance(entrance_exam_minimum_score_pct, float) and entrance_exam_minimum_score_pct.is_integer()) + ): + entrance_exam_minimum_score_pct = entrance_exam_minimum_score_pct / 100 + + course_overview.entrance_exam_minimum_score_pct = entrance_exam_minimum_score_pct course_overview.force_on_flexible_peer_openassessments = course.force_on_flexible_peer_openassessments From 51774808937bbcb336a4b954c270cd8376e9cc7f Mon Sep 17 00:00:00 2001 From: Jansen Kantor Date: Mon, 6 Apr 2026 16:36:19 -0400 Subject: [PATCH 2/2] test: fix entrance exam cutoff test --- .../content/course_overviews/tests/test_course_overviews.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py b/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py index 874c9af2c426..19fc8f18b588 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py @@ -625,6 +625,7 @@ def test_mongo_course_overview_generation(self): CourseOverview.load_from_module_store(course_key) assert CourseOverview.objects.filter(id=course_key).exists() + @override_settings(ENTRANCE_EXAM_MIN_SCORE_PCT=0.5) def test_null_entrance_exam_minimum_score(self): """ Tests that course overview can be created when entrance_exam_minimum_score is null. @@ -632,8 +633,7 @@ def test_null_entrance_exam_minimum_score(self): course = CourseFactory.create() course.entrance_exam_minimum_score_pct = None course_overview = CourseOverview._create_or_update(course) # pylint: disable=protected-access - assert course_overview.entrance_exam_minimum_score_pct == \ - CourseOverview.entrance_exam_minimum_score_pct.field.default + assert course_overview.entrance_exam_minimum_score_pct == 0.5 @ddt.ddt