Title: Django ASGI: send_default_pii triggers request.user.is_authenticated sync access · Issue #5274 · getsentry/sentry-python · GitHub
Open Graph Title: Django ASGI: send_default_pii triggers request.user.is_authenticated sync access · Issue #5274 · getsentry/sentry-python
X Title: Django ASGI: send_default_pii triggers request.user.is_authenticated sync access · Issue #5274 · getsentry/sentry-python
Description: Summary When running Django under ASGI with send_default_pii=True, Sentry’s Django integration calls request.user.is_authenticated in the ASGI event processor. On Django 5.x this triggers lazy session-backed user resolution in an async c...
Open Graph Description: Summary When running Django under ASGI with send_default_pii=True, Sentry’s Django integration calls request.user.is_authenticated in the ASGI event processor. On Django 5.x this triggers lazy sess...
X Description: Summary When running Django under ASGI with send_default_pii=True, Sentry’s Django integration calls request.user.is_authenticated in the ASGI event processor. On Django 5.x this triggers lazy sess...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/5274
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Django ASGI: send_default_pii triggers request.user.is_authenticated sync access","articleBody":"### Summary\nWhen running Django under ASGI with `send_default_pii=True`, Sentry’s Django integration calls `request.user.is_authenticated` in the ASGI event processor. On Django 5.x this triggers lazy session-backed user resolution in an async context and raises `SynchronousOnlyOperation: You cannot call this from an async context`.\n\nThis appears to happen when the request uses Django’s session auth (e.g. Django admin). It does not occur when user objects are already concretely loaded (custom auth middleware). Disabling `send_default_pii` avoids the error.\n\n### Environment\n- Python: 3.11\n- Django: 5.1.2\n- sentry-sdk: 2.48.0\n- Deployment: ASGI (gunicorn + uvicorn worker)\n\n### Steps to Reproduce\n1. Configure Django with `AuthenticationMiddleware` + `SessionMiddleware`.\n2. Run under ASGI.\n3. Configure Sentry with `send_default_pii=True`.\n4. Hit `/admin/` (or any endpoint using Django session auth).\n\n### Actual Behavior\nSentry logs an internal SDK error:\n```\n.../django/utils/functional.py in _setup\n.../sentry_sdk/integrations/django/__init__.py in is_authenticated\nreturn request_user.is_authenticated\n.../sentry_sdk/integrations/django/__init__.py in _set_user_info\nif user is None or not is_authenticated(user):\n.../sentry_sdk/integrations/django/asgi.py in asgi_request_event_processor\n_set_user_info(request, event)\n.../django/contrib/sessions/backends/base.py in _get_session\nreturn self._session_cache\nSynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.\n```\n\n### Expected Behavior\nIn async contexts, the Django integration should avoid touching `request.user` synchronously. Ideally it should use async-safe APIs (e.g. `request.auser()` / `auth.aget_user`) or skip user capture in ASGI when `send_default_pii` is enabled.\n\n### Notes\n- This appears limited to async requests; WSGI does not raise.\n- A workaround is `send_default_pii=False` and manually calling `sentry_sdk.set_user()` after resolving the user asynchronously.\n","author":{"url":"https://github.com/ohnoah","@type":"Person","name":"ohnoah"},"datePublished":"2026-01-05T10:38:34Z","url":"https://github.com/getsentry/sentry-python/issues/5274"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:82d02ffb-6d5c-657d-5174-133433238e0d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C4A:2ADD62:54B89F:71C7CB:6B00A787 |
| html-safe-nonce | 3c8e8551adcc357a726c5ba38334fc65927dcb2780c3101aa6acb1f891611a6b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzRBOjJBREQ2Mjo1NEI4OUY6NzFDN0NCOjZCMDBBNzg3IiwidmlzaXRvcl9pZCI6IjUyNzIwOTQ2OTE0NjUxNDQxOTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1f770fdec14152042dbd5491ef2705d9cfedfd7512dcbffba0725d9681b2e298 |
| hovercard-subject-tag | issue:3781008141 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/5274/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7d15b16598203d476c05d568b00934162a8d9e3a8997359f772e99b89a0c18f4/getsentry/sentry-python/issues/5274 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7d15b16598203d476c05d568b00934162a8d9e3a8997359f772e99b89a0c18f4/getsentry/sentry-python/issues/5274 |
| og:image:alt | Summary When running Django under ASGI with send_default_pii=True, Sentry’s Django integration calls request.user.is_authenticated in the ASGI event processor. On Django 5.x this triggers lazy sess... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ohnoah |
| hostname | github.com |
| expected-hostname | github.com |
| None | 455b493e3402a3a3a06beac5d20bb7db3da060808b220aa48d6a7eca7c59863a |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2f575159976167242d488c0b062eb355c4e198b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width