Skip to content

Commit

Permalink
Merge pull request #384 from vstoykov/fix-350
Browse files Browse the repository at this point in the history
Fixed #350: Error when trying to access width/height after url
  • Loading branch information
vstoykov committed Aug 1, 2016
2 parents 6a8fe5f + d86ec08 commit 6457cf0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion imagekit/files.py
Expand Up @@ -56,7 +56,18 @@ def _get_size(self):

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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generateimage_tag.py
Expand Up @@ -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(), '')

0 comments on commit 6457cf0

Please sign in to comment.