Skip to content

fix(integrations): Skip uninstall on repeated integration DELETE - #129230

Merged
BYK merged 1 commit into
masterfrom
fix/integrations-skip-repeat-uninstall
Nov 3, 2026
Merged

BYK merged 1 commit into
masterfrom
fix/integrations-skip-repeat-uninstall

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

A second DELETE on an org integration that is already pending deletion no longer calls the provider's uninstall() hook. It returns 204 straight away.

Why: OrganizationIntegrationDetailsEndpoint.delete ran uninstall() on every request. The status guard after it stopped a second ScheduledDeletion and audit entry, but not the external call. Discord's and Cursor Origin's hooks only remove the external install when the current org looks like the last one using it, and they skip pending rows when counting. So with two orgs sharing a Discord server:

  • First DELETE from org A: A's row is still active, the hook sees 2 installs and does nothing. A's row becomes pending.
  • Retried DELETE from org A: the hook now sees only org B, calls leave_guild, and the bot leaves the server org B still uses.

Cursor Origin would delete an installation another org still uses to mint tokens, the same way.

Change: return 204 before uninstall() when the org integration is PENDING_DELETION or DELETION_IN_PROGRESS. The first DELETE keeps its current order: uninstall runs while the row is still active, so the hooks still count it.

Not covered: two concurrent first DELETEs can both pass the check before either commits the status change. Closing that window would mean holding a row lock across the external uninstall call, which I didn't want to do here.

Tests:

  • test_repeat_delete_does_not_leave_shared_guild (Discord): fails on master (one leave_guild call), passes with the fix.
  • test_repeat_delete_skips_uninstall: the second DELETE doesn't call uninstall() and adds no extra ScheduledDeletion or audit entry.
  • test_delete_in_progress_skips_uninstall: no uninstall when deletion is already running.

Ran the Discord uninstall tests and the org integration details tests locally (all pass), plus prek and mypy on the changed files.

Fixes #129229. Found during the idempotency audit in #128927.

via @BYK.

--

View Junior Session [Sentry]

A second DELETE on an org integration that is already pending deletion
called the provider's uninstall() hook again. Discord and Cursor Origin
skip pending rows when counting installs, so the retry saw another org
as the last user and removed the shared install it still relies on.

Return 204 before uninstall() when the org integration is already
pending deletion or being deleted.

Fixes #129229

Co-Authored-By: Burak Yigit Kaya <[email protected]>
@sentry-junior
sentry-junior Bot requested review from a team as code owners October 29, 2026 18:50
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 29, 2026
@BYK
BYK enabled auto-merge (squash) November 2, 2026 22:24
BYK added a commit that referenced this pull request Nov 2, 2026
…#129238)

The schema build now fails when an endpoint publishes a `POST`, `PUT`,
`PATCH` or `DELETE` without declaring `idempotent_methods`. Every such
endpoint is declared in this PR, based on the audit in #128927. #129239
adds the CI check that resends each declared write.

**Why:** `idempotent_methods` was opt-in, so a new or changed endpoint
silently came out as "not idempotent" and never got
`x-sentry-idempotent`, even when it qualified. Making the declaration
mandatory means nobody can forget it, and reviewers see the decision in
the diff.

**The gate** (`apidocs/hooks.py`, `api/base.py`):
- `Endpoint.idempotent_methods` now defaults to `None`, meaning
undeclared.
- A published (`PUBLIC` or `PUBLIC_EXPERIMENTAL`) non-safe method on an
endpoint with `None` raises `SentryApiBuildError`, which tells the
author to list the safe methods or set `frozenset()`.
- Reads and unpublished (`PRIVATE`, `EXPERIMENTAL`) methods are not
affected. The existing checks (no safe methods, no methods the endpoint
doesn't implement) are unchanged.
- `apidocs/README.md` now spells out what counts as safe to resend.

**The migration:** 74 endpoint classes in 69 files get one line each.
- **21 operations newly marked**, the ones the audit found safe as-is:
- **POST:** `bulkUpsertOrganizationCodeMappings`,
`linkProjectRepository`, `addOrganizationMemberTeam`
- **PUT:** `updateOrganizationCodeMapping`,
`updateOrganizationDetectors`, `updateOrganizationDiscoverSavedQuery`,
`updateOrganizationExternalUser`, `updateOrganizationForwarding`, link
an existing external issue, `updateOrganizationReleaseFile`,
`updateOrganizationWorkflows`, `updateProjectCodeOwners`, update a
custom inbound filter, bulk update project environments,
`updateProjectEnvironment`, `updateProjectReleaseFile`,
`updateTeamExternalTeam`
- **DELETE:** `deleteOrganizationIssueExternalIssue`, unlink an external
issue, `deleteOrganizationMemberTeam`, `unstarOrganizationServiceSpan`
- **Everything else gets `frozenset()`**, including:
- writes that only need a small fix, like audit-on-change. Each fix
should flip its endpoint's flag in the same PR.
  - DELETEs that answer a resend with 404.
  - `deleteOrganizationIntegration`, until #129230 lands.

**Verification:**
- The schema builds with `--validate --fail-on-warn`.
- Compared with `master`, the generated spec differs only in the 21 new
`x-sentry-idempotent: true` markers.
- `tests/apidocs/test_hooks.py` passes, with new tests for the
missing-declaration error and for undeclared reads and private writes.
- `prek` and mypy pass.
- I also ran the replay check from #129239 on top of this branch. All 24
marked operations passed. The 3 existing ones plus 21 new ones each
succeeded on resend with no new rows, no audit log or other event outbox
entries, and no queued tasks except the converging
`update_code_owners_schema`.

Refs #128927

<!-- junior-request-attribution:start -->
via **BYK**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC08J1NSPU6S%3A1792772794.175999 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC08J1NSPU6S%3A1792772794.175999)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC08J1NSPU6S%3A1792772794.175999/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>
Co-authored-by: Burak Yigit Kaya <[email protected]>
@BYK
BYK merged commit ee6fd51 into master Nov 3, 2026
73 checks passed
@BYK
BYK deleted the fix/integrations-skip-repeat-uninstall branch November 3, 2026 21:31
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.

Repeated integration DELETE runs uninstall() again and can remove a shared install from another org

2 participants