Skip to content

Commit

Permalink
fix: fix restricted run integrity errors
Browse files Browse the repository at this point in the history
We can end up with restricted run records existing in the DB without
a parent_content_key, so we need to remove the parent_content_key
from our update_or_create() SELECT statement. Additionally, ensure
that we remove null-valued defaults from the UPDATE statement, including
the content_uuid.
ENT-9597
  • Loading branch information
iloveagent57 committed Oct 29, 2024
1 parent bf5898a commit 8b90831
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 8b90831

Please sign in to comment.