Repository navigation
fix(migrations): Drop pending deletions before the drift comparison - #127468
Merged
Merged
Conversation
The drift check compares a migrated database with one built from squashed migrations. Columns and tables in step 1 of a safe deletion (MOVE_TO_PENDING) are gone from the migration state but still in the database, so every PR fails the check while any deletion is in flight. Drop them from the migrated database before capturing its schema. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
joshuarli
approved these changes
Oct 14, 2026
joshuarli
marked this pull request as ready for review
October 14, 2026 22:41
…rift check Mirror SafeRemoveField/SafeDeleteModel: drop auto-created M2M through tables with their field or model, leave explicit through models alone, and drop without CASCADE or IF EXISTS so unexpected dependents fail loudly. Add regression tests and run the workflow when the helper changes. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
… suite tests/tools runs under vanilla pytest without sentry installed, so the DB-backed test can't be collected there. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
This was referenced Oct 15, 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.
migrations-drifthas 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/SafeDeleteModelwithDeletionAction.MOVE_TO_PENDING) takes a field or model out of the migration state but leaves it in the database until a laterDELETEmigration 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.pyreadspending_deletion_models/pending_deletion_fieldsfromSentryProjectStateand applies theDELETEhalf of each one, the same waySafeRemoveField/SafeDeleteModelwould:ALTER TABLE ... DROP COLUMNthroughmodels are left alone unless they're pending deletion themselvesCASCADE. There's noCASCADEorIF EXISTS, so an unexpected dependent object or a missing table fails the step instead of being silently dropped or skippedThe 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:sentry_release.new_id, the same failure CI shows.ALTER TABLE "sentry_release" DROP COLUMN "new_id"andtools.migrations.comparereports no drift.tests/sentry/new_migrations/test_drop_pending_deletions.pybuilds 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 undertests/sentrybecause it needs the test database;tests/toolsruns without sentry installed.ruff,mypy,flake8,actionlintand the workflow schema check pass.via @joshuarli.
--
View Junior Session [Sentry]