Defer FileFields causes errors when accessing them
The problem is in FileDescriptor.__get__()
. That method obtains the file directly from instance.__dict__
but, from Django 1.10, deferred fields don't create any item in instance.__dict__
, so a KeyError is raised.
Moreover, ImageFields access the file each time a model is instantiated to update dimension fields, so a KeyError is raised whenever an instance with a deferred ImageField is created.
The obvious solution is change file = instance.__dict__[self.field.name]
for file = instance.__dict__.get(self.field.name)
inside of FileDescriptor.__get__()
but I am not sure about the consequences.
Change History (9)
Triage Stage: |
Unreviewed →
Accepted
|
Triage Stage: |
Accepted →
Ready for checkin
|
Patch needs improvement: |
set
|
Triage Stage: |
Ready for checkin →
Accepted
|
Patch needs improvement: |
unset
|
Resolution: |
→ fixed
|
Status: |
new →
closed
|
A regression test for Django's test suite