Skip to content

fix: sort hybrid migrations after their target to prevent multiple heads#14

Merged
mergify[bot] merged 1 commit intomainfrom
devs/jd/worktree-no-break-on-changes/I3b68dc315a9abaa0cb76c90951b2d8e4d9a663b4
Mar 3, 2026
Merged

fix: sort hybrid migrations after their target to prevent multiple heads#14
mergify[bot] merged 1 commit intomainfrom
devs/jd/worktree-no-break-on-changes/I3b68dc315a9abaa0cb76c90951b2d8e4d9a663b4

Conversation

@jd
Copy link
Member

@jd jd commented Mar 3, 2026

When two branches fork from the same dynamic head and one adds a
dynamic migration while the other adds a hybrid (static with hardcoded
down_revision), the first-merged dynamic and the later-merged hybrid
both pointed to the same predecessor, creating a fork and MultipleHeads.

Fix by sorting hybrids by their target's git_sequence instead of their
own, placing them immediately after their target in the chain.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Copilot AI review requested due to automatic review settings March 3, 2026 16:42
@mergify mergify bot had a problem deploying to Mergify Merge Protections March 3, 2026 16:42 Failure
@mergify
Copy link

mergify bot commented Mar 3, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 🤖 Continuous Integration

Wonderful, this rule succeeded.
  • all of:
    • check-success=all-greens

🟢 👀 Review Requirements

Wonderful, this rule succeeded.
  • any of:
    • #approved-reviews-by>=1
    • author = dependabot[bot]
    • author = mergify-ci-bot

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?:

🟢 🔎 Reviews

Wonderful, this rule succeeded.
  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an Alembic migration ordering edge case where a later-merged “hybrid” (static down_revision pointing to a dynamic revision) could cause the dynamic chain builder to produce multiple heads. The fix adjusts ordering so hybrids are placed immediately after their dynamic target, preventing concurrent-branch insertions from forking the chain.

Changes:

  • Add a regression test covering the “dynamic inserted before hybrid” multiple-heads scenario.
  • Update dynamic participant sorting so hybrids are ordered by their target’s git_sequence rather than their own.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
alembic_git_revisions/_chain.py Changes sort order in _build_dynamic_chain to place hybrid migrations right after their dynamic target revision.
tests/test_chain.py Adds a regression test ensuring the chain avoids multiple heads when a dynamic migration appears in git order before a later-merged hybrid.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

When two branches fork from the same dynamic head and one adds a
dynamic migration while the other adds a hybrid (static with hardcoded
down_revision), the first-merged dynamic and the later-merged hybrid
both pointed to the same predecessor, creating a fork and MultipleHeads.

Fix by sorting hybrids by their target's git_sequence instead of their
own, placing them immediately after their target in the chain.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change-Id: I3b68dc315a9abaa0cb76c90951b2d8e4d9a663b4
Claude-Session-Id: f2902019-6258-4c62-9887-f23b8128665f
@jd jd force-pushed the devs/jd/worktree-no-break-on-changes/I3b68dc315a9abaa0cb76c90951b2d8e4d9a663b4 branch from 19b3c4a to 74e157c Compare March 3, 2026 16:55
@mergify mergify bot requested a review from a team March 3, 2026 16:55
@mergify mergify bot deployed to Mergify Merge Protections March 3, 2026 16:56 Active
@mergify mergify bot merged commit f8091f6 into main Mar 3, 2026
8 checks passed
@mergify mergify bot deleted the devs/jd/worktree-no-break-on-changes/I3b68dc315a9abaa0cb76c90951b2d8e4d9a663b4 branch March 3, 2026 16:58
@mergify
Copy link

mergify bot commented Mar 3, 2026

Merge Queue Status

Rule: default


  • Entered queue2026-03-03 16:58 UTC
  • Checks passed · in-place
  • Merged2026-03-03 16:58 UTC · at 74e157cdecbc90f6ffe97abad30a26dac0d2f216

This pull request spent 8 seconds in the queue, with no time running CI.

Required conditions to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants