From 9a08b1b68548ebb73f51f55d15b07b43b38fa3c7 Mon Sep 17 00:00:00 2001 From: amickan Date: Thu, 12 Dec 2024 12:58:02 +0100 Subject: [PATCH] Address review --- app/grandchallenge/algorithms/forms.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/grandchallenge/algorithms/forms.py b/app/grandchallenge/algorithms/forms.py index a08319d35..a099d39e0 100644 --- a/app/grandchallenge/algorithms/forms.py +++ b/app/grandchallenge/algorithms/forms.py @@ -1409,18 +1409,18 @@ def save(self): algorithm=self._algorithm ).update(is_default=False) - if AlgorithmAlgorithmInterface.objects.filter( + matched_rows = AlgorithmAlgorithmInterface.objects.filter( algorithm=self._algorithm, interface=interface - ).exists(): - AlgorithmAlgorithmInterface.objects.filter( - algorithm=self._algorithm, interface=interface - ).update(is_default=self.cleaned_data["set_as_default"]) - else: + ).update(is_default=self.cleaned_data["set_as_default"]) + + if matched_rows == 0: self._algorithm.interfaces.add( interface, through_defaults={ "is_default": self.cleaned_data["set_as_default"] }, ) + elif matched_rows > 1: + raise RuntimeError("This _really_ shouldn't happen") return interface