Skip to content

Commit

Permalink
Supplicate before the gods of Django and…
Browse files Browse the repository at this point in the history
do not dare to change the name of the `instance` parameter of signal
handlers
  • Loading branch information
jnm committed Feb 22, 2022
1 parent f135154 commit 9979941
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion onadata/apps/logger/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@


@receiver(pre_delete, sender=Attachment)
def pre_delete_attachment(attachment, **kwargs):
def pre_delete_attachment(instance, **kwargs):
# "Model.delete() isn’t called on related models, but the pre_delete and
# post_delete signals are sent for all deleted objects." See
# https://docs.djangoproject.com/en/2.2/ref/models/fields/#django.db.models.CASCADE
# We want to delete all files when an Instance (or Attachment) object is
# deleted.

# `instance` here means "model instance", and no, it is not allowed to
# change the name of the parameter
attachment = instance
try:
attachment.media_file.delete()
except Exception as e:
Expand Down

0 comments on commit 9979941

Please sign in to comment.