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.
* 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>
* status: new => closed
* resolution: => worksforme
--
Ticket URL: <https://code.djangoproject.com/ticket/26049#comment:2>