Skip to content

Commit

Permalink
Merge pull request #4663 from rtibbles/null_extra_fields
Browse files Browse the repository at this point in the history
Prevent errors when extra_fields are null.
  • Loading branch information
rtibbles authored Aug 26, 2024
2 parents 7f689c3 + 2d3ea18 commit f508463
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contentcuration/contentcuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ def mark_complete(self): # noqa C901
except completion_criteria.ValidationError:
errors.append("Mastery criterion is defined but is invalid")
else:
criterion = self.extra_fields.get("options", {}).get("completion_criteria", {})
criterion = self.extra_fields and self.extra_fields.get("options", {}).get("completion_criteria", {})
if criterion:
try:
completion_criteria.validate(criterion, kind=self.kind_id)
Expand Down
18 changes: 18 additions & 0 deletions contentcuration/contentcuration/tests/test_contentnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,3 +1171,21 @@ def test_create_exercise_bad_new_extra_fields(self):
AssessmentItem.objects.create(contentnode=new_obj, question="This is a question", answers="[{\"correct\": true, \"text\": \"answer\"}]")
new_obj.mark_complete()
self.assertFalse(new_obj.complete)

def test_create_video_null_extra_fields(self):
licenses = list(License.objects.filter(copyright_holder_required=False, is_custom=False).values_list("pk", flat=True))
channel = testdata.channel()
new_obj = ContentNode(
title="yes",
kind_id=content_kinds.VIDEO,
parent=channel.main_tree,
license_id=licenses[0],
copyright_holder="Some person",
extra_fields=None,
)
new_obj.save()
File.objects.create(contentnode=new_obj, preset_id=format_presets.VIDEO_HIGH_RES, checksum=uuid.uuid4().hex)
try:
new_obj.mark_complete()
except AttributeError:
self.fail("Null extra_fields not handled")

0 comments on commit f508463

Please sign in to comment.