BufferedFile should have a 'closed' propery #80

Closed
smunaut opened this Issue Sep 10, 2012 · 2 comments

Projects

None yet

3 participants

@smunaut
smunaut commented Sep 10, 2012

The Python file interface seems to publically define a xxx.closed property and some application use it.
Currently there is an internal _closed propery and just exposing it read-only works:

@property
def closed(self):
    return self._closed
@Bockit
Contributor
Bockit commented Oct 17, 2012

I ran into this problem today when running django's collectstatic function with the SFTP backend and some Pipeline'd files.

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
    collected = self.collect()
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 120, in collect
    for original_path, processed_path, processed in processor:
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 239, in post_process
    saved_name = self._save(hashed_name, original_file)
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/storages/backends/sftpstorage.py", line 167, in _save
    content.open()
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/core/files/base.py", line 111, in open
    if not self.closed:
  File "/Users/work/Documents/business-development/smudtodo/venv/lib/python2.7/site-packages/django/core/files/base.py", line 51, in _get_closed
    return not self.file or self.file.closed
AttributeError: 'SFTPFile' object has no attribute 'closed'

I eventually tracked it down to this issue (BufferedFile needing a closed property) and had the same solution as suggested.

@bitprophet bitprophet added a commit that referenced this issue Nov 29, 2012
@bitprophet bitprophet Changelog re #80, fixes #80 f6ed6a8
@bitprophet
Member

Thanks to both of you, this fix works for now. (Reckon eventually we'll want to simply make the "private" var public.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment