#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.e569004afd7262ca9f3dfc9b304125ec%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.