Skip to content

chore(repositories): Switch over queries for RepositoryProjectPathConfig to use the new ProjectRepository table#115516

Open
wedamija wants to merge 1 commit into
danf/repository-project-seerprojectrepofrom
danf/repository-project-codemappings
Open

chore(repositories): Switch over queries for RepositoryProjectPathConfig to use the new ProjectRepository table#115516
wedamija wants to merge 1 commit into
danf/repository-project-seerprojectrepofrom
danf/repository-project-codemappings

Conversation

@wedamija
Copy link
Copy Markdown
Member

@wedamija wedamija commented May 13, 2026

This switches over SeerProjectRepository to start querying repos and projects via ProjectRepository. Also switches over attribute use.

@wedamija wedamija requested a review from a team May 13, 2026 21:28
@wedamija wedamija requested review from a team as code owners May 13, 2026 21:29
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 13, 2026
@wedamija wedamija changed the title chore(repositories): Switch over queries for `RepositoryProjectPathCo… chore(repositories): Switch over queries for RepositoryProjectPathConfig to use the new ProjectRepository table May 13, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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 cf7aa2a. Configure here.

Comment thread src/sentry/models/project.py
@wedamija wedamija requested a review from a team as a code owner May 13, 2026 21:51
@wedamija wedamija force-pushed the danf/repository-project-codemappings branch from 01b14dd to cf7aa2a Compare May 13, 2026 21:51
…nfig` to use the new `ProjectRepository` table

This switches over `SeerProjectRepository` to start querying repos and projects via `ProjectRepository`. Also switches over attribute use.
@wedamija wedamija force-pushed the danf/repository-project-codemappings branch from cf7aa2a to 36d2611 Compare May 13, 2026 21:52
Comment on lines 99 to +103
try:
return RepositoryProjectPathConfig.objects.get(
id=code_mapping_id, project=self.context["project"]
)
if features.has("organizations:project-repository-fk-reads", project.organization):
return RepositoryProjectPathConfig.objects.get(
id=code_mapping_id, project_repository__project=project
)
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 query in validate_code_mapping_id incorrectly filters out older code mappings with a NULL project_repository, causing validation to fail for valid mappings.
Severity: HIGH

Suggested Fix

Modify the query in validate_code_mapping_id to correctly handle RepositoryProjectPathConfig records where project_repository is NULL. This can be achieved by performing two separate queries or by using a more complex query with Q objects to include both records with a matching project_repository__project and those with a NULL project_repository that match on the project field directly.

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/issues/endpoints/serializers.py#L99-L103

Potential issue: When the `organizations:project-repository-fk-reads` feature flag is
enabled, the query in `validate_code_mapping_id` filters `RepositoryProjectPathConfig`
using `project_repository__project=project`. This creates an SQL `INNER JOIN` on the
`project_repository` field. Records created before a prior migration have this field as
`NULL` and are therefore excluded by the join. This causes the query to raise a
`DoesNotExist` exception, which is re-raised as a `ValidationError`. As a result, users
with valid, pre-existing code mappings are incorrectly blocked from creating or updating
CODEOWNERS.

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