Loading django/db/models/fields/files.py +4 −3 Original line number Diff line number Diff line Loading @@ -45,10 +45,10 @@ class FieldFile(File): if not self: raise ValueError("The '%s' attribute has no file associated with it." % self.field.name) def _get_file(self, mode='rb'): def _get_file(self): self._require_file() if not hasattr(self, '_file') or self._file is None: self._file = self.storage.open(self.name, mode) self._file = self.storage.open(self.name, 'rb') return self._file def _set_file(self, file): Loading Loading @@ -77,7 +77,8 @@ class FieldFile(File): size = property(_get_size) def open(self, mode='rb'): self._get_file(mode) self._require_file() self.file.open(mode) # open() doesn't alter the file's contents, but it does reset the pointer open.alters_data = True Loading tests/file_storage/tests.py +0 −10 Original line number Diff line number Diff line Loading @@ -734,16 +734,6 @@ class FileFieldStorageTests(TestCase): self.assertEqual(list(obj.normal.chunks(chunk_size=2)), [b"co", b"nt", b"en", b"t"]) obj.normal.close() def test_filefield_write(self): # Files can be written to. obj = Storage.objects.create(normal=SimpleUploadedFile('rewritten.txt', b'content')) with obj.normal as normal: normal.open('wb') normal.write(b'updated') obj.refresh_from_db() self.assertEqual(obj.normal.read(), b'updated') obj.normal.close() def test_duplicate_filename(self): # Multiple files with the same name get _(7 random chars) appended to them. objs = [Storage() for i in range(2)] Loading Loading
django/db/models/fields/files.py +4 −3 Original line number Diff line number Diff line Loading @@ -45,10 +45,10 @@ class FieldFile(File): if not self: raise ValueError("The '%s' attribute has no file associated with it." % self.field.name) def _get_file(self, mode='rb'): def _get_file(self): self._require_file() if not hasattr(self, '_file') or self._file is None: self._file = self.storage.open(self.name, mode) self._file = self.storage.open(self.name, 'rb') return self._file def _set_file(self, file): Loading Loading @@ -77,7 +77,8 @@ class FieldFile(File): size = property(_get_size) def open(self, mode='rb'): self._get_file(mode) self._require_file() self.file.open(mode) # open() doesn't alter the file's contents, but it does reset the pointer open.alters_data = True Loading
tests/file_storage/tests.py +0 −10 Original line number Diff line number Diff line Loading @@ -734,16 +734,6 @@ class FileFieldStorageTests(TestCase): self.assertEqual(list(obj.normal.chunks(chunk_size=2)), [b"co", b"nt", b"en", b"t"]) obj.normal.close() def test_filefield_write(self): # Files can be written to. obj = Storage.objects.create(normal=SimpleUploadedFile('rewritten.txt', b'content')) with obj.normal as normal: normal.open('wb') normal.write(b'updated') obj.refresh_from_db() self.assertEqual(obj.normal.read(), b'updated') obj.normal.close() def test_duplicate_filename(self): # Multiple files with the same name get _(7 random chars) appended to them. objs = [Storage() for i in range(2)] Loading