#31739 closed Cleanup/optimization (fixed)
Document dependency between HttpRequest stream IO methods and body.
Reported by: | Adam Johnson | Owned by: | Tim Park |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When accessing HttpRequest.body it's possible that it will raise RawPostDataException due to prior use of HttpRequest.read() / readline(). However there is no documentation covering this exception, nor any guidance about solving it. Other exceptions like RequestDataTooBig are covered.
Also the exception message is a little obscure: "You cannot access body after reading from request's data stream" . What's the 'data stream' here?
Change History (8)
comment:1 by , 4 years ago
Easy pickings: | set |
---|
comment:2 by , 4 years ago
Component: | HTTP handling → Documentation |
---|---|
Easy pickings: | unset |
Summary: | Document RawPostDataException → Document dependency between HttpRequest stream IO methods and body. |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 4 years ago
It's a bit generous to say RequestDataTooBig is documented
Yes that's true. But at least one can search for it in the docs and find a sentence.
IMO request's data stream is clear enough, since you're using the stream IO API (
read()
&co.)
It's not always clear that the streaming API has been read, as the body can be read by some other code. The issue came up for me when trying to access .body
after django-rest-framework had used .read()
.
Part of this stuff is undocumented because internal no?
I don't think this is internal - these are exceptions that users can see when trying to use the public interface in .body
/ read()
etc.
I think only a few sentences are needed to describe the possible problems so that anyone trying to debug similar issues has more information to go on.
comment:5 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I'm not entirely convinced here...
RequestDataTooBig
is documented. It's mentioned, yes, but...request's data stream
is clear enough, since you're using the stream IO API (read()
&co.)But I guess we could add a note to the `HttpRequest.read()` docs saying something like, "if read() is used prior to accessing body, body will no longer be available." The body docs link to
read()
saying "see more", but then there's nothing said so some expansion might be good.(Given that all the stream IO methods have the same issue, perhaps the note needs to be in the
body
docs.)