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.
--
Ticket URL: <https://code.djangoproject.com/ticket/26900>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "26900-test.diff" added.
A regression test for Django's test suite
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:1>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/6920 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:3>
Comment (by samuelmaudo):
The patch has a problem with ImageFields, I thought. Since image file is
requiered whenever the model is instantiated, defer a ImageField results
in an extra database query for each object in the QuerySet. That could
generate hundreds of database queries.
--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:4>
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:5>
* needs_better_patch: 1 => 0
Comment:
I've updated the patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:6>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"7c33aa8a87d323f0e8e5368705aa8ba96f9819d0" 7c33aa8a]:
{{{
#!CommitTicketReference repository=""
revision="7c33aa8a87d323f0e8e5368705aa8ba96f9819d0"
Fixed #26900 -- Fixed crash accessing deferred FileFields.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"a03ac61332fe356a60e25d5ecd7d4cd7ee07c345" a03ac613]:
{{{
#!CommitTicketReference repository=""
revision="a03ac61332fe356a60e25d5ecd7d4cd7ee07c345"
[1.10.x] Fixed #26900 -- Fixed crash accessing deferred FileFields.
Backport of 7c33aa8a87d323f0e8e5368705aa8ba96f9819d0 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:8>