[Django] #26049: Request _upload_handlers is immutable?

6 views
Skip to first unread message

Django

unread,
Jan 7, 2016, 2:51:36 AM1/7/16
to django-...@googlegroups.com
#26049: Request _upload_handlers is immutable?
--------------------------------------+--------------------
Reporter: awhillas | Owner: nobody
Type: Uncategorized | Status: new
Component: File uploads/storage | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+--------------------
The documentation states
(https://docs.djangoproject.com/en/1.8/topics/http/file-uploads/#id1)
that you can change the upload hander at the beginning of a view by
inserting an instance of your upload handler at the beginning of, what
turns out to be, an ImmutableList
{{{#!python
request.upload_handlers.insert(0, ProgressBarUploadHandler())
}}}
which is because its... ''immutable''. It `complain()`'s with a weird
error:

You cannot alter upload handlers after the upload has been processed.

which is triggered from `django/utils/datastructures.py` line 500. If one
tries the other approach suggested in the documentation
{{{#!python
request.upload_handlers = [ProgressBarUploadHandler()]
}}}
one gets the same error again only triggered from the setter function in
`django/http/request.py` line 215. So `hasattr(self, '_files')` is true
even though the error reports `No FILES data` for `FILES`. The solution I
came up with that seems to actually use my custom upload hander is:
{{{#!python
request._upload_handlers =
['YoMamasPoject.YoMamasApp.handlers.ProgressBarUploadHandler']
}}}
Which is obviously ugly.
I guess nobody has written a test to test this feature? Is the
`request.upload_handlers` list supposed to be immutable, in which case
change the docs or make it mutable? Also ether the setter function for it
is wrong or the error report about FILES is wrong, one of them needs to
change.

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

Django

unread,
Jan 7, 2016, 12:12:34 PM1/7/16
to django-...@googlegroups.com
#26049: Request _upload_handlers is immutable?
-------------------------------------+-------------------------------------

Reporter: awhillas | Owner: nobody
Type: Uncategorized | Status: new
Component: File | Version: 1.8
uploads/storage |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

The tests are
[https://github.com/django/django/blob/6ea7b6776c79b7a30b32c4f0c1f2658bc49dfe6c/tests/file_uploads/views.py#L111-L125
here].

It sounds like you're running into the issue described in the note
following the section you described:

You can only modify upload handlers before accessing `request.POST` or
`request.FILES` – it doesn’t make sense to change upload handlers after
upload handling has already started. If you try to modify
`request.upload_handlers` after reading from `request.POST` or
`request.FILES` Django will throw an error.

If your view isn't accessing those vlaues, then maybe a middleware is?

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

Django

unread,
Jan 8, 2016, 6:27:26 PM1/8/16
to django-...@googlegroups.com
#26049: Request _upload_handlers is immutable?
-------------------------------------+-------------------------------------
Reporter: awhillas | Owner: nobody
Type: Uncategorized | Status: closed
Component: File | Version: 1.8
uploads/storage | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed

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

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

* status: new => closed
* resolution: => worksforme


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

Reply all
Reply to author
Forward
0 new messages