Ticket #8175: 8175-charmless.diff

File 8175-charmless.diff, 1.1 KB (added by charmless, 7 years ago)

Don't close unopened files in delete. (2nd attempt to upload)

  • django/db/models/fields/files.py

     
    8080    save.alters_data = True
    8181
    8282    def delete(self, save=True):
    83         self.close()
     83        if hasattr(self, '_file'):
     84            self.close()
     85            del self._file
    8486        self.storage.delete(self.name)
    8587
    8688        self._name = None
  • tests/regressiontests/file_storage/models.py

     
    4040>>> p.mug_width
    414116
    4242
     43# delete when file exists:
     44>>> p.delete()
     45
     46# delete when file has been removed
     47>>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb').read()
     48>>> p = Person(name="Joe")
     49>>> p.mugshot.save("mug", ContentFile(image_data))
     50>>> import os
     51>>> os.remove(p.mugshot.path)
     52>>> p.delete()
     53
    4354"""}
    44    
    45  No newline at end of file
     55   
Back to Top