Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix downgrade when normalized down revisions have overlap via depends_on #1376

Closed
wants to merge 4 commits into from

Conversation

saifelse
Copy link
Contributor

@saifelse saifelse commented Dec 7, 2023

Description

When the alembic tree has a migration (a1), with a branched migration (b1) that depends_on that migration, followed by a merge migration that merges (a1) and (b1), running the merge migrations downgrade incorrectly updates the heads to [a1, b1], when it should actually just have [b1]. This then prevents a user from running the upgrade again due to the confusing error:

Requested revision b1 overlaps with other requested revisions a1

The problem occurs in HeadMaintainer.update_to_step which will update the value of heads by calling out into a helper method based on the scenario: deleting branches, creating branches, merging branches, unmerging branches, or the typical non-branched migration. As it turns out, all of these methods have logic to determine the canonical set of heads that should be written, except in the case we are unmerging, resulting in the redundant head.

To fix, we simply remove any ancestors of the target heads from the list of target heads when doing an unmerge.

Fixes #1373

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

@zzzeek
Copy link
Member

zzzeek commented Dec 7, 2023

wow you got it? impressive job! thanks for digging into that code!

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 64492e0 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change 64492e0: https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 39f5ad0 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset 39f5ad0 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

Federico Caselli (CaselIT) wrote:

looks ok

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

{self.bmerge.revision},
)

# Downgrading from bmerge to a1 should return back to heads={"b1"}.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Federico Caselli (CaselIT) wrote:

let's also try with downgrade to b1 (that on main has the same error)

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Federico Caselli (CaselIT) wrote:

Done

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

tests/test_version_traversal.py Show resolved Hide resolved
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision da30dbf of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset da30dbf added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

@sqla-tester
Copy link
Collaborator

Federico Caselli (CaselIT) wrote:

recheck

seems that the ci test crashed. Let's try restarting it

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

@sqla-tester
Copy link
Collaborator

Federico Caselli (CaselIT) wrote:

the ci seems happy now.

Can you add a changelog? Similar to these ones https://github.com/sqlalchemy/alembic/tree/main/docs/build/unreleased

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

@saifelse
Copy link
Contributor Author

Can you add a changelog? Similar to these ones https://github.com/sqlalchemy/alembic/tree/main/docs/build/unreleased

@CaselIT : done!

Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision dc8c7f8 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset dc8c7f8 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5027 has been merged. Congratulations! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants