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
Open
Conversation
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, | ||
| ) |
Contributor
There was a problem hiding this comment.
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.
8312052 to
9fdecb2
Compare
…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.
2ae8d91 to
2d2ee38
Compare
armenzg
approved these changes
May 12, 2026
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.
When creating
RepositoryProjectPathConfigandRepositoryProjectPathConfigrows, we now dual write toProjectRepositoryand store the id in the fk column.