#20619 closed Bug (invalid)
Missing call to super in `WSGIRequest.__init__()`
Reported by: | loic84 | Owned by: | |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Florian Apolloner, tom@… | Triage Stage: | Someday/Maybe |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Change History (20)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Has patch: | set |
---|
I've got two solutions to offer:
- The heavy machinery which enables WSGIRequest to call
super
in__init__()
:
https://github.com/loic/django/compare/ticket20619
- A manual fix for the missing var initialization and a comment to hopefully prevent this from happening again.
comment:3 by , 11 years ago
Severity: | Normal → Release blocker |
---|
comment:4 by , 11 years ago
Cc: | added |
---|
comment:5 by , 11 years ago
+1 to approach 1, but not confident enough in this area of the code base to merge it
comment:6 by , 11 years ago
I am not that happy with approach one since it:
- Adds stuff to HttpRequest which it doesn't need at all since it only uses dicts
- Introduces an extra function call to every GET/POST/etc access
That said, I don't have any better ideas.
comment:7 by , 11 years ago
To be honest, I'm not totally happy showing up on git blame for such a hack, that said it's the most compatible fix I've found.
Do we really need WSGIRequest
to use properties? The comment in HttpRequest.encoding
seems to hint that we do, but I can't figure out when it comes into play. Anyone familiar with this area of Django?
comment:8 by , 11 years ago
I came up with a 3rd option:
A refactor of HttpRequest
and WSGIRequest
that removes all hacks specific to WSGIRequest
from HttpRequest
:
https://github.com/loic/django/compare/ticket20619_take3
That's my favorite option by a big margin.
comment:9 by , 11 years ago
@loic84 - It looks to me like that would change behavior. The lazy evaluation of request.POST
/request.FILES
is important for cases such as setting request.upload_handlers
, as well as the effecting the behavior of accessing request.read()
. That change looks like it'd cause request.POST
/request.FILES
to be loaded if request.GET
is accessed, which is problematic. In other words, accessing request.GET
shouldn't cause the request stream to be consumed and parsed.
comment:10 by , 11 years ago
@tomchristie: You are absolutely right. I added another commit to the same branch that should address this issue.
comment:11 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:12 by , 11 years ago
PR https://github.com/django/django/pull/1311
This should be enough to drop the priority on this ticket in view of 1.6b1. Note that the commit message won't close the ticket, we'll still need a long term solution for the missing call to super
.
While I'm at it, I'll mention that https://github.com/loic/django/compare/ticket20619_take3 addresses two outstanding issues:
- We initialize a mutable at the class level in
HttpRequest._upload_handlers
. WSGIRequest.REQUEST
would go stale if you access it and then change the encoding.
comment:15 by , 11 years ago
Severity: | Release blocker → Normal |
---|
comment:16 by , 11 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:17 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Rebased https://github.com/loic/django/compare/ticket20619_take3 to account for [48ce167d895b7e2a9d00884a4a8679851fa890af].
comment:19 by , 11 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Triage Stage: | Accepted → Someday/Maybe |
I've talked to loic84 on IRC and think there is no evidence that refactoring this piece of code will lead to improving the code. The call to super may be missing, but there is no feature on the horizon to my knowledge (and to loic84's knowledge) that would require it.
Given the central role the HttpRequest class plays in *any application* I'm closing this ticket as invalid and ask to reopen it if an actual use case presents itself to make a sensible decision of the usefulness of this refactor.
TLDR; uneeded code churn with high risk
We can't just call the constructor, because setting the GET, POST, etc. in
HttpRequest.__init__()
will clash with the @property definitions inWSGIRequest
.That said, we need to ensure that future additions to
HttpRequest.__init__()
will also find their way toWSGIRequest
.