Opened 9 years ago
Closed 9 years ago
#26049 closed Uncategorized (worksforme)
Request _upload_handlers is immutable?
Reported by: | Alexander Whillas | Owned by: | nobody |
---|---|---|---|
Component: | File uploads/storage | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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
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
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:
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.
Change History (2)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
The tests are here.
It sounds like you're running into the issue described in the note following the section you described:
If your view isn't accessing those vlaues, then maybe a middleware is?