Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix restricted run integrity errors #990

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions enterprise_catalog/apps/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,20 +953,21 @@ def update_or_create_run(cls, course_run_key, parent_content_key, course_run_dic
a parent course key, and a dictionary of course run metadata.
"""
defaults = _get_defaults_from_metadata(course_run_dict)
# We have to pop these fields from defaults to keep them from
defaults['parent_content_key'] = parent_content_key
# We have to conditionally pop these fields from defaults to keep them from
# being used in the UPDATE statement, because the nested course run
# data from the /api/v1/search/all payload *does not* include the
# course run uuid or aggregation key, which are used by
# _get_defaults_from_metadata() to compute the content type and parent key.
# We additionally pop the content_key field because it's another primary
# identifier used to uniquely identify the record in the non-defaults arguments
# in update_or_create() below.
for key in ['content_key', 'parent_content_key', 'content_type']:
defaults.pop(key, None)
for key in ['content_key', 'content_uuid', 'parent_content_key', 'content_type']:
if not defaults.get(key):
defaults.pop(key)
course_run_record, _ = ContentMetadata.objects.update_or_create(
content_key=course_run_key,
content_type=COURSE_RUN,
parent_content_key=parent_content_key,
defaults=defaults,
)
return course_run_record
Expand Down
Loading