From 9979941838c65dbec3da76db641c8c85de86c6ba Mon Sep 17 00:00:00 2001 From: "John N. Milner" Date: Tue, 22 Feb 2022 12:11:13 -0500 Subject: [PATCH] =?UTF-8?q?Supplicate=20before=20the=20gods=20of=20Django?= =?UTF-8?q?=20and=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit do not dare to change the name of the `instance` parameter of signal handlers --- onadata/apps/logger/signals.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/onadata/apps/logger/signals.py b/onadata/apps/logger/signals.py index e346361f2..04a1ad066 100644 --- a/onadata/apps/logger/signals.py +++ b/onadata/apps/logger/signals.py @@ -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: