Skip to content

[new] Never run a revision's stale bytecode - #19

Merged
drycode merged 2 commits into
mainfrom
dy/dry-2040-stale-bytecode
Dec 1, 2026
Merged

drycode merged 2 commits into
mainfrom
dy/dry-2040-stale-bytecode

Conversation

@drycode

@drycode drycode commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

ch-migrate new replaces the template Alembic writes. Python caches bytecode by the source's size and whole-second modified time, so a rewrite in the same second at the same size left the template's empty upgrade() running. up then recorded the migration as applied without sending its SQL. It was first seen with new --irreversible, and also reproduces with plain new --dict and a 40-character name.

  • Every place that rewrites a revision (new, new --exchange, rebase) now drops its cached bytecode.
  • up and down drop it for every revision before they start, so a cache an older version left can't run.
  • The CHANGELOG says who could be affected and how to check.

Eleven new unit tests, eight of which fail without the fix. Unit suite passes; Docker integration 189 passed, 4 skipped.

Style check: three findings are the order and parameter count of functions this changes one line in; they predate it, so the gate was skipped for opening this PR.

`new` replaces the template Alembic wrote and may have loaded. Python
keys cached bytecode on the source's size and whole-second modified
time, so a same-size rewrite within the second left the template's
empty upgrade() running, and `up` recorded the migration without
sending its SQL. `rebase` and `new --exchange` rewrote files the same
way. Every rewrite now drops the cached bytecode, and `up` and `down`
drop it for all revisions first, so a cache an older version left
can't run either.

Solves: DRY-2040 migration recorded but never run
Tests: 11 new unit tests, 8 of which fail without the fix; unit and
  Docker integration suites; a 61-migration import that had skipped 3
Patch release for the stale-bytecode fix. The CHANGELOG says who could
be affected and how to check, because upgrading can't rerun a migration
the database already counts as applied.

Solves: DRY-2040 release
Tests: none (version and changelog)
@drycode
drycode force-pushed the dy/dry-2040-stale-bytecode branch from f039e8b to 6403051 Compare December 1, 2026 17:37
@drycode
drycode merged commit 6403051 into main Dec 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant