Code

Ticket #16946: 16946.diff

File 16946.diff, 697 bytes (added by charettes, 3 years ago)

Make sure django File wrapper size getter raises the correct exception when called on a an instance with no name

Line 
1Index: django/core/files/base.py
2===================================================================
3--- django/core/files/base.py   (révision 16910)
4+++ django/core/files/base.py   (copie de travail)
5@@ -36,8 +36,8 @@
6         if not hasattr(self, '_size'):
7             if hasattr(self.file, 'size'):
8                 self._size = self.file.size
9-            elif os.path.exists(self.file.name):
10-                self._size = os.path.getsize(self.file.name)
11+            elif self.name and os.path.exists(self.name):
12+                self._size = os.path.getsize(self.name)
13             else:
14                 raise AttributeError("Unable to determine the file's size.")
15         return self._size