#8175 closed (fixed)
FileStorage-rf: Why does 'close' call 'open'?
Reported by: | magneto | Owned by: | nobody |
---|---|---|---|
Component: | File uploads/storage | Version: | dev |
Severity: | Keywords: | filefield fs-rf | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Just got the new FileStorage re-factor, ran a battery of little tests on a site of mine and got this very strange backtrace when trying to delete a file
and YES, there is a signal that does some fancy things with the original file location (likes moves is somewhere rather then really deleting it)
so the file is really 'not' in the original location anymore, but it does seems strange to me that the Field would bounce all the way down to OPEN a file it wants CLOSED
File " assets/views.py" in simple_asset_delete 597. asset.delete() File " assets/models.py" in delete 538. super(Asset, self).delete() File " django/db/models/base.py" in delete 429. delete_objects(seen_objs) File " django/db/models/query.py" in delete_objects 846. signals.post_delete.send(sender=cls, instance=instance) File " django/dispatch/dispatcher.py" in send 133. response = receiver(signal=self, sender=sender, **named) File " django/db/models/fields/files.py" in delete_file 208. file.delete(save=False) File " django/db/models/fields/files.py" in delete 291. super(ImageFieldFile, self).delete(save) File " django/db/models/fields/files.py" in delete 83. self.close() File " django/core/files/base.py" in close 147. self.file.close() File " django/db/models/fields/files.py" in _get_file 45. self._file = self.storage.open(self.name, 'rb') File " django/core/files/storage.py" in open 27. file = self._open(name, mode) File " django/core/files/storage.py" in _open 140. return File(open(self.path(name), mode)) Exception Type: IOError at /delete/asset/86263/ Exception Value: [Errno 2] No such file or directory: u'86/862/86263/mfrohne_2941966_01'
Attachments (3)
Change History (10)
by , 16 years ago
Attachment: | close_open_trap.diff added |
---|
comment:1 by , 16 years ago
Component: | Core framework → File uploads/storage |
---|---|
Has patch: | set |
milestone: | → 1.0 |
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
I'm having a similar issue when deleting files: I've cleared out my uploads directory and now want to remove all the database entries that refer to them*. When I try to do that using the admin, however, it yields a 500 debug page complaining that the file is not open (traceback below).
It doesn't make much sense for delete to complain that the file it's deleting no longer exists. And, as the original reporter notes, 'close' should not call 'open'.
- Yes, this is backwards; I'm cleaning up the upload directories after testing several different ways of generating filenames in an upload_to callback, and just wanted to wipe them all out.
Traceback: File "/Users/typing/software/python-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/Users/typing/software/python-packages/django/contrib/admin/sites.py" in root 172. return self.model_page(request, *url.split('/', 2)) File "/Users/typing/software/python-packages/django/views/decorators/cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/Users/typing/software/python-packages/django/contrib/admin/sites.py" in model_page 189. return admin_obj(request, rest_of_url) File "/Users/typing/software/python-packages/django/contrib/admin/options.py" in __call__ 273. return self.delete_view(request, unquote(url[:-7])) File "/Users/typing/software/python-packages/django/contrib/admin/options.py" in delete_view 750. obj.delete() File "/Users/typing/software/python-packages/django/db/models/base.py" in delete 420. delete_objects(seen_objs) File "/Users/typing/software/python-packages/django/db/models/query.py" in delete_objects 850. signals.post_delete.send(sender=cls, instance=instance) File "/Users/typing/software/python-packages/django/dispatch/dispatcher.py" in send 132. response = receiver(signal=self, sender=sender, **named) File "/Users/typing/software/python-packages/django/db/models/fields/files.py" in delete_file 204. file.delete(save=False) File "/Users/typing/software/python-packages/django/db/models/fields/files.py" in delete 276. super(ImageFieldFile, self).delete(save) File "/Users/typing/software/python-packages/django/db/models/fields/files.py" in delete 83. self.close() File "/Users/typing/software/python-packages/django/core/files/base.py" in close 147. self.file.close() File "/Users/typing/software/python-packages/django/db/models/fields/files.py" in _get_file 45. self._file = self.storage.open(self.name, 'rb') File "/Users/typing/software/python-packages/django/core/files/storage.py" in open 28. file = self._open(name, mode) File "/Users/typing/software/python-packages/django/core/files/storage.py" in _open 128. return File(open(self.path(name), mode)) Exception Type: IOError at /admin/images/image/5/delete/ Exception Value: [Errno 2] No such file or directory: u'/Users/typing/Desktop/spre/media-data/user/jim/images/Property Street Image-Banner.jpg'
by , 16 years ago
Attachment: | 8175-charmless.diff added |
---|
Don't close unopened files in delete. (2nd attempt to upload)
comment:3 by , 16 years ago
I've uploaded a patch with a testcase, but I can't see it in the trac diff view. It's there in the "Original Format" link.
comment:4 by , 16 years ago
Needs tests: | unset |
---|
comment:5 by , 16 years ago
We ran into this issue during the Django sprint in Tel Aviv. +1 for the 2nd charmless patch (the one with the testcase).
try/except around the 'open' step in close()