Skip to content

Commit

Permalink
fix: clear and reset restricted run relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Oct 18, 2024
1 parent b998d40 commit b75dfe8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion enterprise_catalog/apps/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,23 @@ def store_canonical_record(cls, course_metadata_dict):
def store_record_with_query(cls, course_metadata_dict, catalog_query):
filtered_metadata = cls.filter_restricted_runs(course_metadata_dict, catalog_query)
course_record = cls._store_record(filtered_metadata, catalog_query)
relationships = []

for course_run_dict in cls.restricted_runs_for_course(filtered_metadata, catalog_query):
course_run_record, _ = ContentMetadata.objects.get_or_create(
content_key=course_run_dict['key'],
content_type=COURSE_RUN,
defaults=_restricted_content_defaults(course_run_dict),
)
RestrictedRunAllowedForRestrictedCourse.objects.get_or_create(
relationship, _ = RestrictedRunAllowedForRestrictedCourse.objects.get_or_create(
course=course_record, run=course_run_record,
)
relationships.append(relationship)

# We use clear=True to clear and then reset the related allowed runs
# for this restricted course. This is necessary in the case that a previously-allowed
# run becomes unassociated from the restricted course.
course_record.restricted_run_allowed_for_restricted_course.set(relationships, clear=True)
return course_record

@classmethod
Expand Down

0 comments on commit b75dfe8

Please sign in to comment.