Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#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)

close_open_trap.diff (580 bytes ) - added by magneto 16 years ago.
try/except around the 'open' step in close()
8175.charmless.diff (1.1 KB ) - added by charmless 16 years ago.
Don't close unopened files in delete.
8175-charmless.diff (1.1 KB ) - added by charmless 16 years ago.
Don't close unopened files in delete. (2nd attempt to upload)

Download all attachments as: .zip

Change History (10)

by magneto, 16 years ago

Attachment: close_open_trap.diff added

try/except around the 'open' step in close()

comment:1 by Jacob, 16 years ago

Component: Core frameworkFile uploads/storage
Has patch: set
milestone: 1.0
Needs tests: set
Triage Stage: UnreviewedAccepted

comment:2 by charmless, 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 charmless, 16 years ago

Attachment: 8175.charmless.diff added

Don't close unopened files in delete.

by charmless, 16 years ago

Attachment: 8175-charmless.diff added

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

comment:3 by charmless, 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 charmless, 16 years ago

Needs tests: unset

comment:5 by Idan Gazit, 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).

comment:6 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in [8637].

comment:7 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top