feat(middleware): Enable viewer context middleware by default#112293
Merged
feat(middleware): Enable viewer context middleware by default#112293
Conversation
Set the viewer-context.enabled option default to True so the ViewerContextMiddleware populates ViewerContext on every request. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
JoshFerge
approved these changes
Apr 6, 2026
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Default change breaks test relying on old default
- Added @override_options decorator to explicitly set viewer-context.enabled to False in test_skipped_when_disabled, ensuring the test correctly validates disabled middleware behavior.
Or push these changes by commenting:
@cursor push 62bac19e44
Preview (62bac19e44)
diff --git a/tests/sentry/middleware/test_viewer_context.py b/tests/sentry/middleware/test_viewer_context.py
--- a/tests/sentry/middleware/test_viewer_context.py
+++ b/tests/sentry/middleware/test_viewer_context.py
@@ -103,6 +103,7 @@
super().setUp()
self.factory = RequestFactory()
+ @override_options({"viewer-context.enabled": False})
def test_skipped_when_disabled(self):
captured: list = []
@@ -110,7 +111,6 @@
captured.append(get_viewer_context())
return MagicMock(status_code=200)
- # Default: viewer-context.enabled is False
middleware = ViewerContextMiddleware(get_response)
request = self.factory.get("/")This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fa5498b. Configure here.
Add explicit @override_options decorator to set viewer-context.enabled to False, since the default is now True. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Backend Test FailuresFailures on
|
Avoid accessing request.user for ANONYMOUS_STATIC_PREFIXES paths, which would add Vary: Cookie and break HTTP caching for static assets. This matches the pattern used by StaffMiddleware and SuperuserMiddleware. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
joshuarli
added a commit
that referenced
this pull request
Apr 6, 2026
#112293 didn't select anything in sentry or getsentry dispatch for src/sentry/options/defaults.py - this kind of stuff is evaluated at module load (before any test context is active) so we don't have coverage data for it added `src/sentry/options` FULL_SUITE_TRIGGERS and also had claude audit for more stuff to put in there
george-sentry
pushed a commit
that referenced
this pull request
Apr 9, 2026
Enable the `ViewerContextMiddleware` by setting the `viewer-context.enabled` option default to `True`. This causes the middleware to populate a `ViewerContext` (unified caller identity) on every authenticated request. The option uses `FLAG_NOSTORE` so the value is read at process startup from deploy config (`SENTRY_OPTIONS`). Changing the default here means it will be active everywhere unless explicitly overridden to `False` in deploy config. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
george-sentry
pushed a commit
that referenced
this pull request
Apr 9, 2026
#112293 didn't select anything in sentry or getsentry dispatch for src/sentry/options/defaults.py - this kind of stuff is evaluated at module load (before any test context is active) so we don't have coverage data for it added `src/sentry/options` FULL_SUITE_TRIGGERS and also had claude audit for more stuff to put in there
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.


Enable the
ViewerContextMiddlewareby setting theviewer-context.enabledoption default to
True. This causes the middleware to populate aViewerContext(unified caller identity) on every authenticated request.The option uses
FLAG_NOSTOREso the value is read at process startup fromdeploy config (
SENTRY_OPTIONS). Changing the default here means it will beactive everywhere unless explicitly overridden to
Falsein deploy config.