Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8175: don't open files we're about to close. This was a pesky …

…bug to track down; thanks to charmless for tracking it down.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8637 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8943a857a7bcf8aae9edc0eb09719e36f7b9e78c 1 parent c33aeaa
Jacob Kaplan-Moss authored August 27, 2008
7  django/db/models/fields/files.py
@@ -78,7 +78,12 @@ def save(self, name, content, save=True):
78 78
     save.alters_data = True
79 79
 
80 80
     def delete(self, save=True):
81  
-        self.close()
  81
+        # Only close the file if it's already open, which we know by the
  82
+        # presence of self._file
  83
+        if hasattr(self, '_file'):
  84
+            self.close()
  85
+            del self._file
  86
+            
82 87
         self.storage.delete(self.name)
83 88
 
84 89
         self._name = None
6  tests/regressiontests/file_storage/models.py
@@ -40,5 +40,11 @@ class Person(models.Model):
40 40
 >>> p.mug_width
41 41
 16
42 42
 
  43
+# Bug #8175: correctly delete files that have been removed off the file system.
  44
+>>> import os
  45
+>>> p2 = Person(name="Fred")
  46
+>>> p2.mugshot.save("shot", ContentFile(image_data))
  47
+>>> os.remove(p2.mugshot.path)
  48
+>>> p2.delete()
43 49
 """}
44 50
     

0 notes on commit 8943a85

Please sign in to comment.
Something went wrong with that request. Please try again.