From dd28557323c4b4eaa3b351d64b8b9ee2e3eda557 Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Wed, 7 Dec 2011 00:52:06 -0500 Subject: [PATCH] Change handling of spec deletion Though it's not the case with `FileSystemStorage`, attempting to delete a nonexistent file can cause an exception (as in #80). We want to avoid these errors but don't want to suppress others raised in the process of deleting the file, so we first check to see if the file exists. --- imagekit/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/imagekit/models.py b/imagekit/models.py index 90640d3..0f16bb2 100755 --- a/imagekit/models.py +++ b/imagekit/models.py @@ -238,10 +238,11 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile): self.close() del self.file - try: - self.storage.delete(self.name) - except (NotImplementedError, IOError): - pass + if self.name and self.storage.exists(self.name): + try: + self.storage.delete(self.name) + except NotImplementedError: + pass # Delete the filesize cache. if hasattr(self, '_size'):