Skip to content
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

Make reading the request body work in Django ASGI apps. #2495

Merged
merged 15 commits into from Nov 10, 2023

Conversation

antonpirker
Copy link
Member

@antonpirker antonpirker commented Nov 8, 2023

Handle request body in ASGI based Django apps. Starting with Django 4.1 the stream representing the request body is closed immediately preventing us from reading it. This fix reads the request body early on, so it is cached by Django and can be then read by our integration to add to the events sent to Sentry.

Fixes #2375

@antonpirker antonpirker self-assigned this Nov 8, 2023
@antonpirker antonpirker marked this pull request as ready for review November 8, 2023 18:56
@sentrivana
Copy link
Contributor

sentrivana commented Nov 10, 2023

As I was working on the django 5 update I found out that we're not running the asgi django test suite on any version of django 4, because we don't install channels[daphne] which it needs:

Screenshot 2023-11-10 at 09 40 41

Basically this is missing from tox.ini: 96a4d46 But when I added it, the asgi test suite was failing for django 4. Maybe also because of the issue you fixed here?

We should fix that. Not necessarily in this PR, but it might be that the test case you added was actually never executed for django 4.

@sentrivana
Copy link
Contributor

sentrivana commented Nov 10, 2023

Created a separate issue for the asgi tests: #2498 @szokeasaurusrex is taking a look.

Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

👍🏻

sentry_sdk/integrations/django/asgi.py Outdated Show resolved Hide resolved
Co-authored by Daniel Szoke <daniel.szoke@sentry.io>
@sentrivana sentrivana linked an issue Nov 10, 2023 that may be closed by this pull request
@antonpirker antonpirker enabled auto-merge (squash) November 10, 2023 13:54
@antonpirker antonpirker merged commit 35d86b6 into master Nov 10, 2023
313 of 314 checks passed
@antonpirker antonpirker deleted the antonpirker/django_asgi_read_body branch November 10, 2023 14:32
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.

Django ASGI test suite is skipped for Django 4 ValueError: I/O operation on closed file
2 participants