Skip to content

Commit

Permalink
add error to post signal
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnyrose committed Jan 8, 2023
1 parent cfea4ff commit 80a35e7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/django_cleanup/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ def delete_file(sender, instance, field_name, file_, using, reason):
def run_on_commit():
cleanup_pre_delete.send(sender=sender, **event)
success = False
error = None
try:
file_.delete(save=False)
success = True
except Exception:
except Exception as ex:
error = ex
opts = instance._meta
logger.exception(
'There was an exception deleting the file `%s` on field `%s.%s.%s`',
file_, opts.app_label, opts.model_name, field_name)
cleanup_post_delete.send(sender=sender, success=success, **event)
cleanup_post_delete.send(sender=sender, error=error, success=success, **event)

on_commit(run_on_commit, using)

Expand Down

0 comments on commit 80a35e7

Please sign in to comment.