fix(viewer-context): Populate org after request resolution#113139
Open
fix(viewer-context): Populate org after request resolution#113139
Conversation
Set the viewer context organization id at the same points where API request handlers resolve and bind the request organization. This keeps the early middleware behavior intact while making the resolved organization available to code that runs after convert_args on organization, project, team, group, and monitor endpoints. Add focused regression tests for the shared helper and the main endpoint resolution paths. Co-Authored-By: Codex <codex@openai.com>
Update the viewer context organization id inside bind_organization_context instead of repeating the same call at each binding site. This keeps request-scoped enrichment behavior the same while making the canonical organization binding hook responsible for both SDK scope tags and ambient viewer context updates. Co-Authored-By: Codex <codex@openai.com>
Keep the endpoint viewer-context regression tests type-safe by separating the raw WSGI request from the DRF request wrapper used for convert_args. This matches the actual request shapes under test and fixes the backend typing job without changing runtime behavior. Co-Authored-By: Codex <codex@openai.com>
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.
Populate
ViewerContext.organization_idwhen the request organization isresolved in endpoint
convert_argspaths.ViewerContextMiddlewareruns before URL-scoped organization resolution, sosession-authenticated requests could carry a user in the contextvar without an
organization even once the request org had been bound later in dispatch. This
updates the context at the same points where we already set
request._request.organizationfor organization, project, team, group, andmonitor endpoints.
I considered trying to resolve the organization earlier in middleware, but that
would duplicate endpoint-specific lookup logic and still miss cases where the
organization only becomes known through project or group resolution. Keeping the
enrichment at the existing binding sites is narrower and matches the canonical
request lifecycle.
This also adds focused regressions for the shared helper and for the
organization, project, team, and group endpoint resolution paths so the context
keeps the resolved org once
convert_argshas run.