diff --git a/imagekit/files.py b/imagekit/files.py index e7178880..84fa544f 100644 --- a/imagekit/files.py +++ b/imagekit/files.py @@ -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) diff --git a/tests/test_generateimage_tag.py b/tests/test_generateimage_tag.py index 433c86f0..db3f5772 100644 --- a/tests/test_generateimage_tag.py +++ b/tests/test_generateimage_tag.py @@ -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(), '')