Skip to content

Conversation

@Mihir-Mavalankar
Copy link
Contributor

PR Details

  • Add an option to append rather than overwrite repository list for bulk edit endpoints.
  • We use the (organization_id, repo_provider, repo_external_id) as a composite key to uniquely identify a repository.

@Mihir-Mavalankar Mihir-Mavalankar self-assigned this Dec 18, 2025
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 18, 2025
@Mihir-Mavalankar Mihir-Mavalankar marked this pull request as ready for review December 18, 2025 21:14
@Mihir-Mavalankar Mihir-Mavalankar requested a review from a team as a code owner December 18, 2025 21:14
Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

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

lgtm

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #105261      +/-   ##
===========================================
+ Coverage   80.56%    80.58%   +0.01%     
===========================================
  Files        9443      9430      -13     
  Lines      404660    404327     -333     
  Branches    25723     25652      -71     
===========================================
- Hits       326008    325813     -195     
+ Misses      78220     78046     -174     
- Partials      432       468      +36     

Copy link
Member

@billyvg billyvg left a comment

Choose a reason for hiding this comment

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

imo, we shouldn't add this right now since there's not an immediate need for it.

@Mihir-Mavalankar Mihir-Mavalankar enabled auto-merge (squash) December 19, 2025 16:16
Comment on lines +282 to +287
new_repos = [SeerRepoDefinition(**repo_data).dict() for repo_data in repos_data]
if append_repositories:
existing_repos = existing_pref.get("repositories") or []
pref_update["repositories"] = merge_repositories(existing_repos, new_repos)
else:
pref_update["repositories"] = new_repos
Copy link

Choose a reason for hiding this comment

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

Bug: When appending repositories, missing organization_id values can cause incorrect deduplication, leading to repositories being silently dropped because the field is not validated as required.
Severity: MEDIUM | Confidence: High

🔍 Detailed Analysis

When the appendRepositories option is used, the endpoint does not validate that incoming repositories have an organization_id. The RepositorySerializer allows this field to be optional, defaulting to None if omitted. The merge_repositories function uses (organization_id, provider, external_id) as a composite key for deduplication. If multiple repositories are processed with organization_id as None but with the same provider and external_id, they will be incorrectly treated as duplicates. This results in legitimate repositories being silently dropped instead of appended, leading to data loss in the configuration.

💡 Suggested Fix

Either make the organization_id field required in the RepositorySerializer or automatically populate the organization_id from the current organization's context if it is not provided in the request payload. This ensures the deduplication key is always complete.

🤖 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/seer/endpoints/organization_autofix_automation_settings.py#L282-L287

Potential issue: When the `appendRepositories` option is used, the endpoint does not
validate that incoming repositories have an `organization_id`. The
`RepositorySerializer` allows this field to be optional, defaulting to `None` if
omitted. The `merge_repositories` function uses `(organization_id, provider,
external_id)` as a composite key for deduplication. If multiple repositories are
processed with `organization_id` as `None` but with the same `provider` and
`external_id`, they will be incorrectly treated as duplicates. This results in
legitimate repositories being silently dropped instead of appended, leading to data loss
in the configuration.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7764901

@Mihir-Mavalankar Mihir-Mavalankar merged commit 4ad43fe into master Dec 19, 2025
67 checks passed
@Mihir-Mavalankar Mihir-Mavalankar deleted the add-append-option branch December 19, 2025 17:15
@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants