From 538156047fc64355da6bd9062ae9035bf5216e9f Mon Sep 17 00:00:00 2001 From: juan Date: Tue, 8 Oct 2024 10:05:24 +0200 Subject: [PATCH] fix: made other course settings optional in serializers --- lms/djangoapps/ccx/api/v0/serializers.py | 2 +- lms/djangoapps/ccx/api/v0/views.py | 7 ++----- .../0007_customcourseforedx_other_course_settings.py | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lms/djangoapps/ccx/api/v0/serializers.py b/lms/djangoapps/ccx/api/v0/serializers.py index d541016f5968..8d631772d759 100644 --- a/lms/djangoapps/ccx/api/v0/serializers.py +++ b/lms/djangoapps/ccx/api/v0/serializers.py @@ -19,7 +19,7 @@ class CCXCourseSerializer(serializers.ModelSerializer): due = serializers.CharField(allow_blank=True) max_students_allowed = serializers.IntegerField(source='max_student_enrollments_allowed') course_modules = serializers.SerializerMethodField() - other_course_settings = serializers.JSONField() + other_course_settings = serializers.JSONField(required=False, allow_null=True) class Meta: model = CustomCourseForEdX diff --git a/lms/djangoapps/ccx/api/v0/views.py b/lms/djangoapps/ccx/api/v0/views.py index acd1afff4754..4ee0b1d34c44 100644 --- a/lms/djangoapps/ccx/api/v0/views.py +++ b/lms/djangoapps/ccx/api/v0/views.py @@ -153,11 +153,8 @@ def get_valid_input(request_data, ignore_missing=False): field_errors['max_students_allowed'] = {'error_code': 'null_field_max_students_allowed'} other_course_settings = request_data.get('other_course_settings') - if other_course_settings is not None: - if isinstance(other_course_settings, dict): - valid_input['other_course_settings'] = other_course_settings - else: - field_errors['other_course_settings'] = {'error_code': 'invalid_other_course_settings_type'} + if other_course_settings and isinstance(other_course_settings, dict): + valid_input['other_course_settings'] = other_course_settings course_modules = request_data.get('course_modules') if course_modules is not None: diff --git a/lms/djangoapps/ccx/migrations/0007_customcourseforedx_other_course_settings.py b/lms/djangoapps/ccx/migrations/0007_customcourseforedx_other_course_settings.py index 11f3ec22b966..d10368b45b21 100644 --- a/lms/djangoapps/ccx/migrations/0007_customcourseforedx_other_course_settings.py +++ b/lms/djangoapps/ccx/migrations/0007_customcourseforedx_other_course_settings.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.17 on 2024-10-07 10:53 +# Generated by Django 3.2.17 on 2024-10-08 11:22 from django.db import migrations, models @@ -13,6 +13,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='customcourseforedx', name='other_course_settings', - field=models.JSONField(blank=True, default=dict(), null=True, verbose_name='Custom Json Content'), + field=models.JSONField(blank=True, default={}, null=True, verbose_name='Custom Json Content'), ), ]