Skip to content

feat(api): Accept project slugs in organization filters#117446

Merged
gricha merged 16 commits into
masterfrom
feat/project-id-or-slug-resolver
Jun 12, 2026
Merged

feat(api): Accept project slugs in organization filters#117446
gricha merged 16 commits into
masterfrom
feat/project-id-or-slug-resolver

Conversation

@gricha

@gricha gricha commented Jun 11, 2026

Copy link
Copy Markdown
Member

Organization project resolution now accepts project IDs, slugs, or mixed ID-and-slug values through the canonical project query parameter. Permission checks still run through get_projects(), legacy projectSlug filters keep existing runtime precedence, existing projectSlug OpenAPI fields remain available, empty project filters are treated as absent, and stats endpoints preserve permission-scoped project materialization when grouping by project.

This PR is stacked on #117445 and intentionally stops at the shared organization resolver, generic API docs, stats, and combined-alert callers. Product-specific endpoint opt-ins are split into separate draft PRs against this resolver branch.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 11, 2026
@gricha gricha marked this pull request as ready for review June 11, 2026 19:38
@gricha gricha requested review from a team as code owners June 11, 2026 19:38
Comment thread src/sentry/api/bases/organization.py
Comment thread src/sentry/api/bases/organization.py
class OrganizationParams:
PROJECT_ID_OR_SLUG = OpenApiParameter(
name="project_id_or_slug",
PROJECT_SLUG = OpenApiParameter(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're intending to drop this it we can probably just remove this from the docs

Comment thread src/sentry/apidocs/parameters.py Outdated
type=int,
description="""The IDs of projects to filter by. `-1` means all available projects.
type=str,
description="""The IDs or slugs of projects to filter by. Project slugs are unique within each organization. Omit this parameter to include all accessible projects. `-1` is also accepted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we say """
-1 is also accepted to include all accessible projects?
"""

@gricha gricha requested review from a team as code owners June 11, 2026 20:36
Comment thread src/sentry/api/endpoints/organization_stats_v2.py Outdated
Comment thread src/sentry/api/endpoints/organization_stats_v2.py Outdated
@gricha gricha requested a review from a team as a code owner June 11, 2026 20:40
gricha added a commit that referenced this pull request Jun 12, 2026
Add a shared project ID-or-slug parser and DRF field for endpoints that
explicitly opt in to accepting either identifier. Existing ProjectField
behavior stays slug-only by default, while id_allowed=True can now
resolve project IDs or slugs within the current organization and
permission context.

This is the foundation PR for the project slug API split. It only
introduces the helper, serializer support, and focused tests; endpoint
resolver behavior lands in the stacked follow-up PR #117446.

Co-authored-by: OpenAI GPT-5.5 <noreply@openai.com>
Base automatically changed from feat/project-id-or-slug-foundation to master June 12, 2026 01:01
gricha and others added 5 commits June 11, 2026 18:02
Update the organization project resolver so the existing project query parameter can resolve IDs, slugs, or mixed ID-and-slug filters with the same permission checks as project IDs. Preserve legacy projectSlug precedence and align release-permission cache keys with the effective project scope.

Co-Authored-By: OpenAI GPT-5.5 <noreply@openai.com>
Keep existing endpoints that only understand numeric project IDs working while the new organization resolver accepts project IDs or slugs. Add regression coverage that slugs are ignored by the compatibility helper.

Co-Authored-By: OpenAI GPT-5.5 <noreply@openai.com>
Allow project query slugs to be parsed when callers pass an empty project ID set from numeric-only compatibility helpers. Keep release-permission cache keys aligned with the same project-resolution precedence.

Co-Authored-By: OpenAI GPT-5.5 <noreply@openai.com>
Use the ID-or-slug request parser in endpoints that previously inspected only numeric project IDs before resolving projects. This prevents slug-only project filters from becoming membership-wide or org-wide queries.

Add endpoint regression coverage for stats, combined rules, and notification actions.

Co-Authored-By: OpenAI GPT-5.5 <noreply@openai.com>
Document project as the ID-or-slug organization filter and remove the legacy projectSlug parameter from endpoint schemas. Also clarify that -1 means all accessible projects.

Co-Authored-By: OpenAI GPT-5.5 <noreply@openai.com>
gricha and others added 5 commits June 11, 2026 21:18
Keep project query documentation focused on numeric project IDs while retaining the all-project sentinel wording.

Co-Authored-By: OpenCode <noreply@opencode.ai>
Let project-aware endpoints resolve request project filters through get_projects so mixed numeric IDs and slugs are not truncated to IDs only.

Co-Authored-By: OpenCode <noreply@opencode.ai>
Document project as the canonical ID-or-slug query parameter while avoiding promotion of the legacy projectSlug parameter name.

Co-Authored-By: OpenCode <noreply@opencode.ai>
Use exact all-project sentinel detection and multi-value groupBy checks so stats v2 still materializes permission-scoped projects when grouping by project.

Co-Authored-By: OpenCode <noreply@opencode.ai>
Keep the existing projectSlug OpenAPI parameter available while documenting project as the preferred ID-or-slug query parameter.

Co-Authored-By: OpenCode <noreply@opencode.ai>
gricha and others added 2 commits June 12, 2026 00:19
Centralize legacy projectSlug precedence and blank project filter cleanup for serializers that validate both project parameters.

Co-Authored-By: OpenCode <noreply@opencode.ai>
Keep the pre-existing project_id_or_slug query parameter on endpoints that already exposed it while continuing to prefer the canonical project filter.

Co-Authored-By: OpenCode <noreply@opencode.ai>
@gricha gricha requested a review from JoshFerge June 12, 2026 16:27
gricha and others added 2 commits June 12, 2026 09:42
Expose a focused helper for serializers that only need blank project query values treated as absent. Keep the projectSlug precedence helper layered on top.

Co-Authored-By: OpenCode <noreply@opencode.ai>
Advertise project ID-or-slug inputs as integer or string in OpenAPI so generated clients can keep passing numeric project IDs while also supporting slugs.

Co-Authored-By: OpenCode <noreply@opencode.ai>

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a9dcf02. Configure here.

Comment thread src/sentry/notifications/api/endpoints/notification_actions_index.py Outdated
Treat exact all-project filters as organization-wide listing requests so projectSlug= keeps organization-level notification actions while specific project filters still exclude them.

Co-Authored-By: OpenCode <noreply@opencode.ai>

@JoshFerge JoshFerge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me.

Describe project query parameters as arrays whose items accept project IDs or slugs. This preserves generated client typing without triggering drf-spectacular warnings for many=True on a non-basic schema.

Co-Authored-By: OpenCode <noreply@opencode.ai>
@gricha gricha merged commit bc1df2d into master Jun 12, 2026
84 of 85 checks passed
@gricha gricha deleted the feat/project-id-or-slug-resolver branch June 12, 2026 18:50
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