Skip to content

chore(repositories): Dual write to the new ProjectRepository table when created related rows in other tables#115346

Open
wedamija wants to merge 1 commit into
danf/repository-project-linkfrom
danf/repository-project-dual-write
Open

chore(repositories): Dual write to the new ProjectRepository table when created related rows in other tables#115346
wedamija wants to merge 1 commit into
danf/repository-project-linkfrom
danf/repository-project-dual-write

Conversation

@wedamija
Copy link
Copy Markdown
Member

When creating RepositoryProjectPathConfig and RepositoryProjectPathConfig rows, we now dual write to ProjectRepository and store the id in the fk column.

@wedamija wedamija requested review from a team as code owners May 11, 2026 22:42
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 11, 2026
Comment on lines +132 to +137
organization_integration_id=self.org_integration.id,
organization_id=self.context["organization"].id,
integration_id=self.context["organization_integration"].integration_id,
project_repository=project_repo,
**validated_data,
)
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 update() method in RepositoryProjectPathConfigSerializer doesn't update the project_repository foreign key, which can lead to the code mapping being deleted unexpectedly.
Severity: HIGH

Suggested Fix

Update the update() method in RepositoryProjectPathConfigSerializer to fetch or create the correct ProjectRepository instance based on the new project_id and repository_id. Assign this new instance to the project_repository field of the RepositoryProjectPathConfig instance, mirroring the logic in the create() method.

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/integrations/api/endpoints/organization_code_mappings.py#L132-L137

Potential issue: When a user updates an existing code mapping's project or repository
via the `OrganizationCodeMappingDetailsEndpoint.put` endpoint, the `update()` method in
`RepositoryProjectPathConfigSerializer` is called. This method updates the `project_id`
and `repository_id` fields but fails to update the `project_repository` foreign key. The
code mapping remains linked to the old `ProjectRepository` record. Because the
`project_repository` field has `on_delete=models.CASCADE`, if the old
`ProjectRepository` is ever deleted (e.g., by unlinking the old repository from the old
project), the updated code mapping will be unintentionally deleted as well.

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

@wedamija wedamija requested a review from a team May 11, 2026 23:24
@wedamija wedamija force-pushed the danf/repository-project-link branch from 8312052 to 9fdecb2 Compare May 11, 2026 23:57
@wedamija wedamija requested review from a team as code owners May 11, 2026 23:57
…when created related rows in other tables

When creating `RepositoryProjectPathConfig` and `RepositoryProjectPathConfig` rows, we now dual write to `ProjectRepository` and store the id in the fk column.
@wedamija wedamija force-pushed the danf/repository-project-dual-write branch from 2ae8d91 to 2d2ee38 Compare May 11, 2026 23:59
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.

1 participant