diff --git a/contentcuration/contentcuration/models.py b/contentcuration/contentcuration/models.py index 4ecd370cf9..7dea52878a 100644 --- a/contentcuration/contentcuration/models.py +++ b/contentcuration/contentcuration/models.py @@ -1886,7 +1886,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) diff --git a/contentcuration/contentcuration/tests/test_contentnodes.py b/contentcuration/contentcuration/tests/test_contentnodes.py index 6c24498bfb..d9b0ae235d 100644 --- a/contentcuration/contentcuration/tests/test_contentnodes.py +++ b/contentcuration/contentcuration/tests/test_contentnodes.py @@ -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")