Repository navigation
fix(integrations): Skip uninstall on repeated integration DELETE - #129230
Merged
Merged
Conversation
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]>
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]>
cvxluo
approved these changes
Nov 3, 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.
A second
DELETEon an org integration that is already pending deletion no longer calls the provider'suninstall()hook. It returns 204 straight away.Why:
OrganizationIntegrationDetailsEndpoint.deleteranuninstall()on every request. The status guard after it stopped a secondScheduledDeletionand 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: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 isPENDING_DELETIONorDELETION_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 (oneleave_guildcall), passes with the fix.test_repeat_delete_skips_uninstall: the second DELETE doesn't calluninstall()and adds no extraScheduledDeletionor 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
prekand mypy on the changed files.Fixes #129229. Found during the idempotency audit in #128927.
via @BYK.
--
View Junior Session [Sentry]