Skip to content

Commit 6b25d24

Browse files
authored
Fixed #31706 -- Removed unnecessary getattr() call in FileDescriptor.__get__().
refresh_from_db() loads fields values.
1 parent a8473b4 commit 6b25d24

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

django/db/models/fields/files.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,9 @@ def __get__(self, instance, cls=None):
173173

174174
# The instance dict contains whatever was originally assigned
175175
# in __set__.
176-
if self.field.name in instance.__dict__:
177-
file = instance.__dict__[self.field.name]
178-
else:
176+
if self.field.name not in instance.__dict__:
179177
instance.refresh_from_db(fields=[self.field.name])
180-
file = getattr(instance, self.field.name)
178+
file = instance.__dict__[self.field.name]
181179

182180
# If this value is a string (instance.file = "path/to/file") or None
183181
# then we simply wrap it with the appropriate attribute class according

0 commit comments

Comments
 (0)