Skip to content

Commit cba9062

Browse files
committed
fixup! move assertion up
1 parent b545445 commit cba9062

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

evap/evaluation/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,12 +1372,13 @@ class Meta:
13721372
unique_together = [("question", "questionnaire")]
13731373

13741374
def delete(self, using=None, keep_parents=False) -> tuple[int, dict[str, int]]:
1375+
assert not self.question.answer_class.objects.filter(assignment=self).exists(), (
1376+
"cannot delete question with answers"
1377+
)
13751378
count = 0
13761379
meta: dict[str, int] = {}
13771380

13781381
if not self.question.questionnaires.exclude(pk=self.questionnaire.pk).exists():
1379-
if self.question.answer_class.objects.filter(assignment=self).exists():
1380-
raise AssertionError("cannot delete question with answers")
13811382
count, meta = self.question.delete(using=using, keep_parents=False) # garbage-collect unused questions
13821383
self_count, self_meta = super().delete(using=using, keep_parents=keep_parents)
13831384
return count + self_count, meta | self_meta

0 commit comments

Comments
 (0)