Opened 8 years ago
Closed 8 years ago
#27606 closed Bug (fixed)
Error in formatting HttpResponseRedirect when __init__() raises DisallowedHost
Reported by: | Jerome Leclanche | Owned by: | Jerome Leclanche |
---|---|---|---|
Component: | HTTP handling | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
When initializing an HttpResponseRedirect with a redirect url that does not match the allowed_schemes
attribute, the DisallowedRedirect exception is raised before super(HttpResponseRedirectBase, self).__init__(*args, **kwargs)
is called, which sets self._headers
.
This causes repr()ing/printing the response to error out with AttributeError: 'HttpResponseRedirect' object has no attribute '_headers'.
Ref: django/http/response.py (HttpResponseRedirectBase)
Attachments (1)
Change History (14)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
comment:2 by , 8 years ago
Component: | Uncategorized → HTTP handling |
---|
comment:3 by , 8 years ago
The easiest way to reproduce it is to initialize HttpResponseRedirect("invalid-scheme://foo")
from a django view and look at the resulting debug variables. It's a trivial error as it *should* only appear when catching the exception and debugging it.
comment:4 by , 8 years ago
Thanks. HttpResponseBase
aliases __str__ = serialize_headers
. A solution could be to define a complete __str__
that uses the value of super()
if self._headers
isn't set. I'm not sure it's worth it. Is the formatting error more than a minor cosmetic problem?
comment:5 by , 8 years ago
In 95% of cases it's just a cosmetic issue on the django debug page, but I suspect it might actually obscure other bugs, especially if someone is using Sentry or a similar exception catcher.
Is there a reason why the exception is raised before super()? It seems incorrect to do so at first glance.
follow-up: 7 comment:6 by , 8 years ago
Easy pickings: | set |
---|---|
Summary: | Error in formatting HttpResponseRedirect → Error in formatting HttpResponseRedirect when __init__() raises DisallowedHost |
Triage Stage: | Unreviewed → Accepted |
I think it would be fine.
comment:7 by , 8 years ago
Replying to Tim Graham:
I think it would be fine.
Do you mean it would be fine to call super before raising the exception?
comment:9 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:11 by , 8 years ago
Has patch: | set |
---|---|
Needs tests: | set |
comment:12 by , 8 years ago
Needs tests: | unset |
---|
Could you provide a complete snippet or a test for Django's test suite that demonstrates the problem?