Skip to content

perf(api): Add collapse=organization to project details endpoint#113140

Open
scttcper wants to merge 1 commit intomasterfrom
scttcper/collapse-project-org
Open

perf(api): Add collapse=organization to project details endpoint#113140
scttcper wants to merge 1 commit intomasterfrom
scttcper/collapse-project-org

Conversation

@scttcper
Copy link
Copy Markdown
Member

@scttcper scttcper commented Apr 15, 2026

The project details endpoint serializes the full organization through OrganizationSummarySerializer which fetches avatars, auth provider config, and computes feature flags. When the caller only needs the org id and slug, ?collapse=organization skips all of that and returns a minimal object.

Could shave off 400ms of the current project details 500ms request time.

The project details endpoint serializes the full organization through
OrganizationSummarySerializer which fetches avatars, auth provider
config, and computes feature flags. When the caller only needs the org
id and slug, `?collapse=organization` skips all of that and returns a
minimal object.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 15, 2026
@scttcper scttcper marked this pull request as ready for review April 15, 2026 23:53
@scttcper scttcper requested a review from a team as a code owner April 15, 2026 23:53
@scttcper scttcper requested review from a team April 15, 2026 23:54
Comment on lines +983 to +992
if self._collapse(ORGANIZATION_KEY):
orgs = {
str(i.organization_id): {
"id": str(i.organization_id),
"slug": i.organization.slug,
}
for i in item_list
}
else:
orgs = {d["id"]: d for d in serialize(list({i.organization for i in item_list}), user)}
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.

Bug: The collapse=organization parameter returns a minimal object instead of omitting the organization key, which is inconsistent with other collapse parameters in the API.
Severity: LOW

Suggested Fix

To ensure API consistency, modify the serializer to completely omit the organization field from the response when collapse=organization is specified, matching the behavior of other collapse parameters.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/sentry/api/serializers/models/project.py#L983-L992

Potential issue: The handling of `collapse=organization` in the
`DetailedProjectSerializer` is inconsistent with other `collapse` parameters in the API.
While other parameters like `latestDeploys` cause the corresponding key to be omitted
from the response, `collapse=organization` results in the `organization` key being
present but with a minimal object containing only `id` and `slug`. This violates the
established pattern for this feature, creating a semantic inconsistency. A client
expecting the key to be absent when collapsed, based on behavior elsewhere, may function
incorrectly.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants