Fixed #350: Error when trying to access width/height after url

If the file is closed and something is calling `open` now the file will be opened correctly event if it was already closed
This commit is contained in:
Venelin Stoykov 2016-07-17 05:08:01 +03:00
parent 23a243c51e
commit d86ec082f1
2 changed files with 13 additions and 2 deletions

View file

@ -56,7 +56,18 @@ class BaseIKFile(File):
def open(self, mode='rb'):
self._require_file()
self.file.open(mode)
try:
self.file.open(mode)
except ValueError:
# if the underlaying file can't be reopened
# then we will use the storage to try to open it again
if self.file.closed:
# clear cached file instance
del self.file
# Because file is a property we can acces it after
# we deleted it
return self.file.open(mode)
raise
def _get_closed(self):
file = getattr(self, '_file', None)

View file

@ -50,7 +50,7 @@ def test_single_dimension_attr():
def test_assignment_tag():
ttag = r"""{% generateimage 'testspec' source=img as th %}{{ th.url }}"""
ttag = r"""{% generateimage 'testspec' source=img as th %}{{ th.url }}{{ th.height }}{{ th.width }}"""
clear_imagekit_cache()
html = render_tag(ttag)
assert_not_equal(html.strip(), '')