0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Only close image if it wasn't already open

Fixes #1256
This commit is contained in:
Karl Hobley 2015-05-06 13:12:46 +01:00
parent b445f2a28f
commit 6ae8213e05
2 changed files with 8 additions and 3 deletions

View File

@ -95,13 +95,19 @@ class AbstractImage(models.Model, TagSearchable):
# these from IOErrors elsewhere in the process
raise SourceImageIOError(text_type(e))
image_file.open('rb')
# Open file if it is closed
close_file = False
if image_file.closed:
image_file.open('rb')
close_file = True
image_file.seek(0)
try:
yield WillowImage.open(image_file)
finally:
image_file.close()
if close_file:
image_file.close()
def get_rect(self):
return Rect(0, 0, self.width, self.height)

View File

@ -238,7 +238,6 @@ class TestGetWillowImage(TestCase):
self.assertTrue(self.image.file.closed)
@unittest.expectedFailure
def test_doesnt_close_open_image(self):
# This tests that when the image file is already open, get_willow_image doesn't close it (#1256)
self.image.file.open('rb')