Skip to content

Commit d0e557c

Browse files
feat: backfill the newest run's display_name as the name of the catalog course
1 parent 92d6b20 commit d0e557c

1 file changed

Lines changed: 3 additions & 13 deletions

File tree

openedx/core/djangoapps/content/course_overviews/migrations/0030_backfill_new_catalog_courseruns.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def backfill_openedx_catalog(apps, schema_editor):
3131
CourseRun = apps.get_model("openedx_catalog", "CourseRun")
3232

3333
created_catalog_course_ids: set[int] = set()
34-
all_course_runs = CourseIndex.objects.filter(base_store="mongodb", library_version="").order_by("course_id")
34+
all_course_runs = CourseIndex.objects.filter(base_store="mongodb", library_version="").order_by("-pk")
3535
for course_idx in all_course_runs:
3636
org_code: str = course_idx.course_id.org
3737
course_code: str = course_idx.course_id.course
@@ -93,24 +93,14 @@ def backfill_openedx_catalog(apps, schema_editor):
9393
org_id=org_data["id"],
9494
course_code=course_code,
9595
defaults={
96+
# The default display_name for the catalog course will be the same name as the newest run, since we
97+
# iterate over "all_course_runs" in "-pk" order (should be same as reverse chronological)
9698
"display_name": display_name,
9799
"language": language,
98100
},
99101
)
100102
if cc_created:
101103
created_catalog_course_ids.add(cc.pk)
102-
elif cc.pk in created_catalog_course_ids:
103-
# This CatalogCourse was previously created during this same migration
104-
# Check if all the runs have the same display_name:
105-
if (
106-
course_overview
107-
and course_overview.display_name
108-
and course_overview.display_name != cc.display_name
109-
and cc.display_name != course_code
110-
):
111-
# The runs have different names, so just use the course code as the common catalog course name.
112-
cc.display_name = course_code
113-
cc.save(update_fields=["display_name"])
114104

115105
if cc.course_code != course_code:
116106
raise ValueError(

0 commit comments

Comments
 (0)