fix: Read request body after handler so receive stream is not deprived#4832
Open
alexander-alderman-webb wants to merge 20 commits intomasterfrom
Open
fix: Read request body after handler so receive stream is not deprived#4832alexander-alderman-webb wants to merge 20 commits intomasterfrom
alexander-alderman-webb wants to merge 20 commits intomasterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4832 +/- ##
==========================================
+ Coverage 84.58% 84.83% +0.25%
==========================================
Files 158 158
Lines 16521 16595 +74
Branches 2867 2877 +10
==========================================
+ Hits 13974 14079 +105
+ Misses 1703 1670 -33
- Partials 844 846 +2
|
Contributor
Author
|
Closing for the reasons in #4764 (comment) |
Contributor
Author
|
Reopening because there may be the option of changing data fields on transactions in a minor version. Users with our FastAPI integration are facing empty receive streams when using |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Ensure endpoint handler runs before the FastAPI or Starlette integrations read the request body.
As the integrations previously called high-level Starlette
Requestmethods early, the underlying ASGI receive stream was consumed before the user's handler or middleware ran. While theRequestobject caches the request body, any handler or middleware that relies on low-level stream access still failed.The event handler that sets
request.datais now registered after the HTTP request is handled. Therequest.dataattribute may no longer be attached to events emitted while the request is processed. In particular, ifNote that
pydanticalso relies on FastAPI/Starlette accessors sorequest.datamay still be available even if the user only implicitly uses the high-level accessors.Issues
Closes #4764
Closes #4827
Closes PY-1851
Closes PY-1831
Reminders
tox -e linters.feat:,fix:,ref:,meta:)