Skip to content

Commit 4a93947

Browse files
authored
Fix container protection and image deletion (#4005)
If container images fail imports then they should not be protected. Sometimes the image will not be set at all so it can immediately be marked as removed. Closes DIAGNijmegen/rse-grand-challenge-admin#514
1 parent 495a22d commit 4a93947

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

app/grandchallenge/components/tasks.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def remove_container_image_from_registry(
349349
@acks_late_2xlarge_task(ignore_errors=(InstanceInUse,))
350350
def delete_container_image(*, pk: uuid.UUID, app_label: str, model_name: str):
351351
from grandchallenge.algorithms.models import AlgorithmImage, Job
352+
from grandchallenge.components.models import ComponentImage
352353
from grandchallenge.evaluation.models import Evaluation, Method
353354
from grandchallenge.workstations.models import WorkstationImage
354355

@@ -359,7 +360,9 @@ def delete_container_image(*, pk: uuid.UUID, app_label: str, model_name: str):
359360
model = apps.get_model(app_label=app_label, model_name=model_name)
360361
instance = model.objects.get(pk=pk)
361362

362-
if isinstance(instance, Method):
363+
if instance.import_status == ComponentImage.ImportStatusChoices.FAILED:
364+
should_be_protected = False
365+
elif isinstance(instance, Method):
363366
should_be_protected = Evaluation.objects.filter(
364367
method=instance,
365368
status=Evaluation.SUCCESS,
@@ -381,9 +384,10 @@ def delete_container_image(*, pk: uuid.UUID, app_label: str, model_name: str):
381384

382385
if instance.image:
383386
instance.image.delete(save=False)
384-
instance.is_removed = True
385-
instance.is_desired_version = False
386-
instance.save()
387+
388+
instance.is_removed = True
389+
instance.is_desired_version = False
390+
instance.save()
387391

388392

389393
def push_container_image(*, instance):

0 commit comments

Comments
 (0)