Pārlūkot izejas kodu

Fixed #31706 -- Removed unnecessary getattr() call in FileDescriptor.__get__().

refresh_from_db() loads fields values.
Sultan 4 gadi atpakaļ
vecāks
revīzija
6b25d24a57
1 mainītis faili ar 2 papildinājumiem un 4 dzēšanām
  1. 2 4
      django/db/models/fields/files.py

+ 2 - 4
django/db/models/fields/files.py

@@ -173,11 +173,9 @@ class FileDescriptor:
 
         # The instance dict contains whatever was originally assigned
         # in __set__.
-        if self.field.name in instance.__dict__:
-            file = instance.__dict__[self.field.name]
-        else:
+        if self.field.name not in instance.__dict__:
             instance.refresh_from_db(fields=[self.field.name])
-            file = getattr(instance, self.field.name)
+        file = instance.__dict__[self.field.name]
 
         # If this value is a string (instance.file = "path/to/file") or None
         # then we simply wrap it with the appropriate attribute class according