-
Notifications
You must be signed in to change notification settings - Fork 499
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Django integration: You cannot access body after reading from request's data stream #3045
Comments
Hi @Audiopolis, I attempted to reproduce your issue using this code, but I did not observe the error message that you reported. Can you please clarify how exactly you encountered this issue? If possible, please share a reproduction with me (you can also do so by opening a PR on my reproduction repo and sharing a link to the PR here). |
@szokeasaurusrex Thanks for trying. I will try to create a reproduction. In the meantime, I'll clarify how I encountered the issue: We send an email from a Django view using Resend. In this environment, Resend does not recognize the domain, so it throws an error. We catch that error and use The original request is automatically converted from an |
Same error is also happening inside Sentry with SDK 2.1.1:
Can be seen here: https://cloudlogging.app.goo.gl/yfAdqBdmA8iER8ZQ8 (retricted link) |
So just to expand on what was already written here, the way DRF works is that it wraps the native Django We capture the data here. Basically, The quick "fix" would be to capture Wasn't able to repro this yet -- @Audiopolis What does the request look like in your app? I assume it's a POST? Does it contain any form data, uploaded files, etc.? Do you access anything on the request in the view? |
Thanks for the additional context @sentrivana. I don't have the full body anymore, but I believe it was indeed a POST request containing a JSON payload. All the logic succeeded (including feeding the payload into a serializer that validated the data and used it to create an object) until it attempted to send an email through a third-party service, which failed, triggering an exception log. In other words, the DRF request has been read multiple times, and at some point, it seems to stop being a DRF request. We are using this middleware:
In this environment, we are also using I have not had time yet to try to create a reproduction. |
How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.0.1
Steps to Reproduce
Environment info:
django=5.0.4
djangorestframework=3.15.1
Expected Result
Either the exception is successfully logged to Sentry, or it's not sent to Sentry at all since it's a log entry and not an unhandled exception.
Actual Result
The text was updated successfully, but these errors were encountered: