Handle exception while saving course display name.

This commit introduces error check for a special case
where the root course does not exists and a data migration
is attempting to save it.
This commit is contained in:
Taranjeet Singh
2018-09-18 16:06:48 +05:30
parent 27cf027a79
commit 02be16dff8

View File

@@ -3,6 +3,7 @@
from __future__ import unicode_literals
from django.db import migrations
from django.http import Http404
import json
import logging
@@ -28,7 +29,11 @@ def save_display_name(apps, schema_editor):
# Create `display_name` overrides for these CCX courses
for ccx in ccx_list:
course = get_course_by_id(ccx.course_id, depth=None)
try:
course = get_course_by_id(ccx.course_id, depth=None)
except Http404:
log.error('Root course %s not found. Skipping saving course display name', ccx.course_id)
continue
display_name = course.fields['display_name']
display_name_json = display_name.to_json(ccx.display_name)
serialized_display_name = json.dumps(display_name_json)