diff options
author | Tim Graham <timograham@gmail.com> | 2016-07-15 15:54:11 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-07-16 08:22:24 -0400 |
commit | 7c33aa8a87d323f0e8e5368705aa8ba96f9819d0 (patch) | |
tree | 209b3f70add084d1c0e82f61d25a10f3141fc35c /django/db/models/fields/files.py | |
parent | 255fb992845e987ef36e3d721a77747a0b2df620 (diff) | |
download | django-7c33aa8a87d323f0e8e5368705aa8ba96f9819d0.tar.gz |
Fixed #26900 -- Fixed crash accessing deferred FileFields.
Diffstat (limited to 'django/db/models/fields/files.py')
-rw-r--r-- | django/db/models/fields/files.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index 8dfd9bf08d..659bb4c518 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -168,7 +168,11 @@ class FileDescriptor(object): # The instance dict contains whatever was originally assigned # in __set__. - file = instance.__dict__[self.field.name] + if self.field.name in instance.__dict__: + file = instance.__dict__[self.field.name] + else: + instance.refresh_from_db(fields=[self.field.name]) + file = getattr(instance, 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 @@ -439,9 +443,10 @@ class ImageField(FileField): Dimensions can be forced to update with force=True, which is how ImageFileDescriptor.__set__ calls this method. """ - # Nothing to update if the field doesn't have dimension fields. + # Nothing to update if the field doesn't have dimension fields or if + # the field is deferred. has_dimension_fields = self.width_field or self.height_field - if not has_dimension_fields: + if not has_dimension_fields or self.attname not in instance.__dict__: return # getattr will call the ImageFileDescriptor's __get__ method, which |