Skip to content

Commit

Permalink
Delete generated resources when workflow run is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyyzhang03 committed Jul 7, 2023
1 parent eb9365d commit d0e93df
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rodan-main/code/rodan/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from django.urls import reverse
from rodan.constants import task_status
from rodan.models.resourcelabel import ResourceLabel
from rodan.models.output import Output
from rodan.models.user import User
from django.db.models.signals import post_delete
from django.dispatch import receiver

import logging

Expand Down Expand Up @@ -298,3 +301,12 @@ def get_viewer(self):
def viewer_relurl(self):
if self.get_viewer() is not None:
return reverse("resource-viewer-acquire", args=(self.uuid,))

@receiver(post_delete, sender=Output)
def post_output_delete(sender, instance, **kwargs):
"""
Deletes resource when associated output is deleted. Cascade delete does not work due to on_delete=PROTECT in Output model.
In newer Django versions, we can use on_delete=models.RESTRICT in Output model to allow cascade delete to work.
"""
if instance.resource:
instance.resource.delete()

0 comments on commit d0e93df

Please sign in to comment.