summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSultan <alosultan@ksu.edu.sa>2020-06-15 08:26:49 +0300
committerGitHub <noreply@github.com>2020-06-15 07:26:49 +0200
commit6b25d24a5755bb90c037e2afd485668bae8f179e (patch)
tree81ae87ba00ec12fc8beddffdab7790388c5959b3
parenta8473b4d348776d823b7a83c1795279279cf3ab5 (diff)
Fixed #31706 -- Removed unnecessary getattr() call in FileDescriptor.__get__().
refresh_from_db() loads fields values.
-rw-r--r--django/db/models/fields/files.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index b682db414c..0fffd6f3c1 100644
--- a/django/db/models/fields/files.py
+++ b/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