Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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 Adam Johnson, 4 years ago

Easy pickings: set

comment:2 by Carlton Gibson, 4 years ago

Component: HTTP handlingDocumentation
Easy pickings: unset
Summary: Document RawPostDataExceptionDocument dependency between HttpRequest stream IO methods and body.
Triage Stage: UnreviewedAccepted

I'm not entirely convinced here...

  • It's a bit generous to say RequestDataTooBig is documented. It's mentioned, yes, but...
  • IMO request's data stream is clear enough, since you're using the stream IO API (read() &co.)
  • Part of this stuff is undocumented because internal no?

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.)

comment:3 by Adam Johnson, 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:4 by Mariusz Felisiak, 4 years ago

Has patch: set
Owner: changed from nobody to Tim Park
Status: newassigned

comment:5 by Carlton Gibson, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 060576b0:

Fixed #31739 -- Documented dependency between HttpRequest stream IO methods and body.

comment:7 by Carlton Gibson <carlton.gibson@…>, 4 years ago

In 3756a05:

[3.1.x] Fixed #31739 -- Documented dependency between HttpRequest stream IO methods and body.

Backport of 060576b0abac460d72714e300aa709d1e7a87dd7 from master

comment:8 by Carlton Gibson <carlton.gibson@…>, 4 years ago

In 502349ce:

[3.0.x] Fixed #31739 -- Documented dependency between HttpRequest stream IO methods and body.

Backport of 060576b0abac460d72714e300aa709d1e7a87dd7 from master

Note: See TracTickets for help on using tickets.
Back to Top