feat(api): Add project ID-or-slug parser#117445
Merged
Merged
Conversation
Add a shared project ID-or-slug field and parser for endpoints that opt in to accepting either identifier. Keep existing ProjectField behavior slug-only by default and add tests for parser, serializer, and numeric slug invariants. Co-Authored-By: OpenAI GPT-5.5 <noreply@openai.com>
Comment on lines
39
to
+43
| else: | ||
| project = Project.objects.get(organization=self.context["organization"], slug=data) | ||
| project_slug = self._validate_slug(data) | ||
| project = Project.objects.get( | ||
| organization=self.context["organization"], slug=project_slug | ||
| ) |
Contributor
There was a problem hiding this comment.
Bug: An invalid project slug raises a generic validation error instead of the intended "Invalid project" error because the specific ValidationError is not caught.
Severity: LOW
Suggested Fix
Modify the except block in ProjectField.to_internal_value to also catch serializers.ValidationError. Inside the handler, raise a new serializers.ValidationError with the intended 'Invalid project' message to ensure consistent error reporting for all invalid project identifiers.
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/rest_framework/project.py#L39-L43
Potential issue: The `try...except` block in `ProjectField.to_internal_value` is
intended to catch lookup failures and return a `ValidationError` with the message
"Invalid project". However, when an invalid slug format is used (e.g., containing a
space), the underlying `ProjectIdOrSlugField` raises a `serializers.ValidationError`
before the database lookup occurs. This validation error is not caught by the `except
Project.DoesNotExist` handler, causing a generic slug format error to be returned to the
user instead of the intended, more specific "Invalid project" message.
Did we get this right? 👍 / 👎 to inform future reviews.
JoshFerge
approved these changes
Jun 11, 2026
cvxluo
approved these changes
Jun 11, 2026
gricha
added a commit
that referenced
this pull request
Jun 12, 2026
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. --------- Co-authored-by: OpenAI GPT-5.5 <noreply@openai.com> Co-authored-by: OpenCode <noreply@opencode.ai>
3 tasks
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.
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.