From 192d49f6a4d52bd04037555f9bdf80eafe604996 Mon Sep 17 00:00:00 2001 From: kiritofeng Date: Wed, 18 Dec 2024 02:12:08 +0000 Subject: [PATCH] Remove `contest_object` from submissions whose problem is removed from contest; fixes #2349 --- judge/signals.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/judge/signals.py b/judge/signals.py index ce4c5d4612..c54554b46b 100644 --- a/judge/signals.py +++ b/judge/signals.py @@ -9,8 +9,8 @@ from django.dispatch import receiver from .caching import finished_submission -from .models import BlogPost, Comment, Contest, ContestSubmission, EFFECTIVE_MATH_ENGINES, Judge, Language, License, \ - MiscConfig, Organization, Problem, Profile, Submission, WebAuthnCredential +from .models import BlogPost, Comment, Contest, ContestProblem, ContestSubmission, EFFECTIVE_MATH_ENGINES, Judge, \ + Language, License, MiscConfig, Organization, Problem, Profile, Submission, WebAuthnCredential def get_pdf_path(basename: str) -> Optional[str]: @@ -79,6 +79,13 @@ def contest_update(sender, instance, **kwargs): for engine in EFFECTIVE_MATH_ENGINES]) +@receiver(post_delete, sender=ContestProblem) +def contest_problem_delete(sender, instance, **kwargs): + # `contest_object` is the `Contest` object indirectly associated with the `Submission` object + # `contest` is the `ContestSubmission` object associated with the `Submission` object + Submission.objects.filter(contest_object=instance.contest, contest__isnull=True).update(contest_object=None) + + @receiver(post_save, sender=License) def license_update(sender, instance, **kwargs): cache.delete(make_template_fragment_key('license_html', (instance.id,)))