BaseRequest: misleading name of has_body attribute #2005
Closed
Description
Long story short
class BaseRequest has attribute has_body that has an unfortunate name as it checks if there are more bytes to read from its body. And when the body is read it changes its value to False. This fact is not obvious from attribute name neither documentation and it causes confusion and bugs.
Expected behavior
has_body should stay static over a lifetime of a request. Or the attribute name and a related documentation should be more specific about the fact that once a body of a request is read, the value has changed.
Actual behavior
has_body return False if a request has a body but was read by another method such as await request.json().
Steps to reproduce
Simple handler that shows this behavior.
async def handler(request):
"""Simple request handler."""
# Let's say request has a JSON body
request.has_body # This returns True
body = await request.json()
request.has_body # This returns FalseYour environment
Not an environment specific.