Commit c88a7011 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Fix ordering for 'purge' deletion of events and superevents

GroupObjectPermission and data directory cleanup should only happen
*after* the event or superevent row is removed from the relevant
table.
parent 70228aa7
Pipeline #66591 passed with stages
in 15 minutes and 45 seconds
......@@ -401,7 +401,7 @@ class Event(models.Model):
# Fool! Save yourself!
self.save()
def delete(self, purge=False, *args, **kwargs):
def delete(self, purge=True, *args, **kwargs):
"""
Optionally override the delete method for Event models.
By default, deleting an Event deletes corresponding subclasses
......@@ -414,10 +414,19 @@ class Event(models.Model):
event.delete(purge=True) will also remove the data directory
and GroupObjectPermissions for the Event and its subclasses
"""
# Store datadir and pk before delete - the pk will be set to None
# by removal from the database, and thus, the datadir won't be
# correct anymore, since it depends on the pk
pk = self.pk
datadir = self.datadir
# Call base class delete
super(Event, self).delete(*args, **kwargs)
# If the database entry was deleted, then we are good to proceed on
# purging everything else (if specified)
if purge:
# Delete data directory
datadir = self.datadir
if os.path.isdir(datadir):
shutil.rmtree(datadir)
......@@ -429,12 +438,10 @@ class Event(models.Model):
cls in f.related_model.__bases__)]
for m in subclasses + [cls]:
ctype = ContentType.objects.get_for_model(m)
gops = GroupObjectPermission.objects.filter(object_pk=self.id,
gops = GroupObjectPermission.objects.filter(object_pk=pk,
content_type=ctype)
gops.delete()
# Call base class delete
super(Event, self).delete(*args, **kwargs)
class EventLog(CleanSaveModel, LogBase, AutoIncrementModel):
"""
......
......@@ -192,13 +192,20 @@ class Superevent(CleanSaveModel, AutoIncrementModel):
self.events.add(self.preferred_event)
def delete(self, purge=True, *args, **kwargs):
if purge:
# Delete data directory
if os.path.isdir(self.datadir):
shutil.rmtree(self.datadir)
# Store datadir before deletion from database
datadir = self.datadir
# Call base class delete
super(Superevent, self).delete(*args, **kwargs)
if purge:
# GOPs are deleted automatically since we have a special class
# for them that is attached directly to the superevent
# Delete data directory
if os.path.isdir(datadir):
shutil.rmtree(datadir)
def event_compatible(self, event):
"""
Check whether an event is of the correct type to be part of this
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment