Skip to content

Inspect Flask bodies read from the raw stream - #792

Open
hansott wants to merge 5 commits into
mainfrom
fix/record-raw-body2
Open

hansott wants to merge 5 commits into
mainfrom
fix/record-raw-body2

Conversation

@hansott

@hansott hansott commented Nov 12, 2026

Copy link
Copy Markdown
Member

No description provided.

if not chunk:
break
chunks.append(chunk)
size -= len(chunk)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_up_to reassigns size on each loop iteration, so the parameter no longer represents the original requested size.

Details

✨ AI Reasoning
​This is Python code, and read_up_to repeatedly decrements its size parameter as the loop consumes chunks. That makes the original requested size unavailable under its original name while the function runs.

🔧 How do I fix it?
Create new local variables instead of reassigning parameters. Use different variable names to clearly distinguish between input and modified values.

Reply on this comment to give feedback or ignore the issue.
More info



class PrefixedStream(io.RawIOBase):
"""Serves bytes that were already read, then the rest of the stream"""

@aikido-pr-checks aikido-pr-checks Bot Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PrefixedStream docstring only restates that it serves the prefix before the underlying stream, which is already apparent from the class and implementation.

Suggested change
"""Serves bytes that were already read, then the rest of the stream"""
Details

✨ AI Reasoning
​The class name and readinto implementation already show that this stream serves the prefix before reading the underlying stream. The docstring adds no reason or other context.

Reply on this comment to give feedback or ignore the issue.
More info

Comment on lines +76 to +77
attribute = getattr(self._stream, name)
if name == "read1":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getattr(self._stream, name) is unnecessary for loaded seek and tell calls, which return the corresponding _source method. Check that case before looking up the attribute on _stream.

Show fix
Suggested change
attribute = getattr(self._stream, name)
if name == "read1":
if name in ("seek", "tell") and self._source is not None:
return getattr(self._source, name)
attribute = getattr(self._stream, name)
if name == "read1":
Details

✨ AI Reasoning
​When the source has already been loaded and the requested attribute is seek or tell, the method is returned from _source. Looking up the same attribute on _stream first does not contribute to that result and can prevent the intended return if the original stream lacks the attribute.

Reply on this comment to give feedback or ignore the issue.
More info

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants