[Django] #26900: Defer FileFields causes errors when accessing them

8 views
Skip to first unread message

Django

unread,
Jul 15, 2016, 7:22:55 AM7/15/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
----------------------------------------------+--------------------
Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.10
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26900>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 15, 2016, 9:16:37 AM7/15/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
------------------------------------------+----------------------------

Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.10
Severity: Release blocker | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+----------------------------
Changes (by timgraham):

* Attachment "26900-test.diff" added.

A regression test for Django's test suite

Django

unread,
Jul 15, 2016, 9:16:46 AM7/15/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
-------------------------------------+-------------------------------------

Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:1>

Django

unread,
Jul 15, 2016, 4:13:25 PM7/15/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
-------------------------------------+-------------------------------------

Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6920 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:2>

Django

unread,
Jul 15, 2016, 5:16:56 PM7/15/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
-------------------------------------+-------------------------------------

Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:3>

Django

unread,
Jul 15, 2016, 6:15:35 PM7/15/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
-------------------------------------+-------------------------------------

Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jul 15, 2016, 6:39:07 PM7/15/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
-------------------------------------+-------------------------------------

Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:5>

Django

unread,
Jul 15, 2016, 8:06:57 PM7/15/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
-------------------------------------+-------------------------------------

Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


Comment:

I've updated the patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/26900#comment:6>

Django

unread,
Jul 16, 2016, 8:47:22 AM7/16/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
-------------------------------------+-------------------------------------
Reporter: samuelmaudo | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Jul 16, 2016, 9:01:12 AM7/16/16
to django-...@googlegroups.com
#26900: Defer FileFields causes errors when accessing them
-------------------------------------+-------------------------------------
Reporter: samuelmaudo | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages