Skip to content

chore(releases): stop dual-writing release new_id - #127438

Merged
ldelvoye merged 1 commit into
masterfrom
ldelvoye/chore/remove-release-new-id-dual-write
Oct 14, 2026
Merged

ldelvoye merged 1 commit into
masterfrom
ldelvoye/chore/remove-release-new-id-dual-write

Conversation

@ldelvoye

Copy link
Copy Markdown
Member

resolves INFRENG-672

Removes the new_id dual-write on Release and takes the column out of Django's model state.

The early id reservation in save() and bulk_create only existed so new_id could go in the same INSERT, so it goes too, and parse_semver_pre_save is back to checking instance.id. The migration makes new_id nullable before the state-only SafeRemoveField, since it refuses a non-null column without a db_default; the column stays in Postgres for servers on the previous release and is dropped in INFRENG-673.

Drops the id pre-claiming that only existed to fill `new_id` in the
same INSERT, and takes the column out of model state. It stays in
Postgres for app servers still on the previous release; the drop
follows in a later PR.
@ldelvoye
ldelvoye requested review from a team as code owners October 14, 2026 20:45
@linear-code

linear-code Bot commented Oct 14, 2026

Copy link
Copy Markdown

INFRENG-672

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1211_release_drop_new_id_pending.py

for 1211_release_drop_new_id_pending in sentry

--
-- Alter field new_id on release
--
ALTER TABLE "sentry_release" ALTER COLUMN "new_id" DROP NOT NULL;
--
-- Moved release.new_id field to pending deletion state
--
-- (no-op)

@ldelvoye
ldelvoye merged commit 79af5a0 into master Oct 14, 2026
89 of 90 checks passed
@ldelvoye
ldelvoye deleted the ldelvoye/chore/remove-release-new-id-dual-write branch October 14, 2026 22:27
joshuarli added a commit that referenced this pull request Oct 14, 2026
…127468)

`migrations-drift` has failed on every run for the last 100 runs (back
to Sep 30), including on PRs that don't touch the drifting tables.

The check compares a database built by running migrations with one built
from squashed migrations. Step 1 of a safe deletion (`SafeRemoveField` /
`SafeDeleteModel` with `DeletionAction.MOVE_TO_PENDING`) takes a field
or model out of the migration state but leaves it in the database until
a later `DELETE` migration drops it. The squashed schema never has it,
so the check fails for as long as any deletion is in flight. Its own
output already says "drift due to step 1 of deletion is normal".

On current master that's `sentry_release.new_id`, which #127438 moved to
pending deletion.

**Fix:** a new `tools/migrations/drop_pending_deletions.py` reads
`pending_deletion_models` / `pending_deletion_fields` from
`SentryProjectState` and applies the `DELETE` half of each one, the same
way `SafeRemoveField` / `SafeDeleteModel` would:
- scalar fields: `ALTER TABLE ... DROP COLUMN`
- many-to-many fields and models: their auto-created through tables are
dropped with them; explicit `through` models are left alone unless
they're pending deletion themselves
- through tables are dropped before the tables they join, so nothing
needs `CASCADE`. There's no `CASCADE` or `IF EXISTS`, so an unexpected
dependent object or a missing table fails the step instead of being
silently dropped or skipped
- each database only gets the statements the router would migrate there

The workflow runs it right before capturing `schema-before`, and now
also triggers on changes to the helper.

**Checked locally against master (`79af5a0d`), following the workflow's
steps:**
- Without the new step: drift on `sentry_release.new_id`, the same
failure CI shows.
- With it: the step runs `ALTER TABLE "sentry_release" DROP COLUMN
"new_id"` and `tools.migrations.compare` reports no drift.
- `tests/sentry/new_migrations/test_drop_pending_deletions.py` builds
real tables for a scalar field, an auto-created and an explicit-through
M2M field, a model with an M2M, and unrelated models, then checks
exactly what's dropped and what's kept. 4 of its 5 tests fail against
the previous version of the helper. It lives under `tests/sentry`
because it needs the test database; `tests/tools` runs without sentry
installed.
- `ruff`, `mypy`, `flake8`, `actionlint` and the workflow schema check
pass.

<!-- junior-request-attribution:start -->
via @joshuarli.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC8V02RHC7%3A1791911755.006269 -->

--

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

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

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Joshua Li <14209781+joshuarli@users.noreply.github.com>
ldelvoye added a commit that referenced this pull request Oct 15, 2026
resolves INFRENG-673

Drops the old int4 `new_id` column from `sentry_release`, the last step
of widening `release.id` to int8. 1211 already moved it to pending, so
nothing in the app reads or writes it. Please hold the merge until
#127438 has finished deploying everywhere.
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.

2 participants