Skip to content

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

Merged
antonpirker merged 15 commits into
masterfrom
antonpirker/django_asgi_read_body
Nov 10, 2023
Merged

Make reading the request body work in Django ASGI apps.#2495
antonpirker merged 15 commits into
masterfrom
antonpirker/django_asgi_read_body

Conversation

@antonpirker

@antonpirker antonpirker commented Nov 8, 2023

Copy link
Copy Markdown
Contributor

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

sentrivana commented Nov 10, 2023

Copy link
Copy Markdown
Contributor

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

sentrivana commented Nov 10, 2023

Copy link
Copy Markdown
Contributor

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

@sentrivana sentrivana left a comment

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.

👍🏻

Comment thread sentry_sdk/integrations/django/asgi.py Outdated
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
@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