- Notifications
You must be signed in to change notification settings - Fork345
fix: use .read() instead of .content.read() in aiohttp transport#1899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
fix: use .read() instead of .content.read() in aiohttp transport#1899
Conversation
Using .read() is more robust when working with caching libraries likeaiohttp-client-cache, which may cause .content.read() to return emptybytes on subsequent reads. .read() ensures the full body is returned.Fixes#1248
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me toReactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more atjules.google/docs. |
Using .read() is more robust when working with caching libraries likeaiohttp-client-cache, which may cause .content.read() to return emptybytes on subsequent reads. .read() ensures the full body is returned.Fixes#1248
chalmerlowe left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
daniel-sanche left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
Uh oh!
There was an error while loading.Please reload this page.
Fixes issue where response content is empty when using
aiohttp-client-cacheby usingresponse.read()instead ofresponse.content.read().Rationale:
In
aiohttp,.read()is the standard, high-level method for reading the full response body. It correctly handles internal state (like caching the body for subsequent calls), which is essential for compatibility with wrappers likeaiohttp-client-cache. Accessing.content.read()directly bypasses this logic, leading to empty responses when the stream has already been consumed or intercepted by the caching layer.Benefits:
google-authis used in conjunction withaiohttpwrappers or middleware.aiohttpbest practices for consuming response bodies.Risk Mitigation:
_CombinedResponseis designed to load the full response into memory. Changing to.read()preserves this behavior exactly; it just uses a safer accessor.aiohttp's.read()returns a reference to the bytes, there is no additional memory overhead compared to the previous implementation.PR created automatically by Jules for task3355868403646689815 started by@chalmerlowe