1
0
mirror of https://github.com/django/django.git synced 2024-12-23 09:36:06 +00:00

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

refresh_from_db() loads fields values.
This commit is contained in:
Sultan 2020-06-15 08:26:49 +03:00 committed by GitHub
parent a8473b4d34
commit 6b25d24a57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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