Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

[1.2.X] Fixed #15364 -- Ensure files are closed correctly during file…

… tests. Thanks to Mila for the report and patch.

Backport of r15604 from trunk.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent e636db1 commit bf4507f255f7fb2e162fbe5b228ef3f380f223ed @freakboy3742 freakboy3742 committed
Showing with 4 additions and 0 deletions.
  1. +4 −0 tests/modeltests/files/
4 tests/modeltests/files/
@@ -27,6 +27,7 @@ def test_files(self):
self.assertEqual(, "tests/django_test.txt")
self.assertEqual(obj1.normal.size, 7)
self.assertEqual(, "content")
+ obj1.normal.close()
# File objects can be assigned to FileField attributes, but shouldn't
# get committed until the model it's attached to is saved.
@@ -46,6 +47,7 @@ def test_files(self):
self.assertEqual(, "con")
self.assertEqual(, "tent")
self.assertEqual(list(obj1.normal.chunks(chunk_size=2)), ["co", "nt", "en", "t"])
+ obj1.normal.close()
# Save another file with the same name.
obj2 = Storage()
@@ -78,12 +80,14 @@ def test_files(self):
obj3 = Storage.objects.create()
self.assertEqual(, "tests/default.txt")
self.assertEqual(, "default content")
+ obj3.default.close()
# But it shouldn't be deleted, even if there are no more objects using
# it.
obj3 = Storage()
self.assertEqual(, "default content")
+ obj3.default.close()
# Verify the fix for #5655, making sure the directory is only
# determined once.

0 comments on commit bf4507f

Please sign in to comment.
Something went wrong with that request. Please try again.