-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Downgrading with multiple Dependencies on a revision throws exception when these dependencies are referenced from other branches #377
Comments
Michael Bayer (@zzzeek) wrote: nice test! here's a graph:
my first impression was that there was some mathematical impossibility going on, but looking at the graph it seems like there's just some treatment of a "dependency" more like a downgrade target that isn't reachable. |
Changes by Michael Bayer (@zzzeek):
|
cloew (@cloew) wrote: Yeah, form what I could tell. The problem is that both of 642c's dependencies are included in the b1 branch. In Alembic 0.8.6, I saw that the RevisionStep.should_delete_branch always treats merges (things with multiple dependencies) as points where new heads should be created. |
Michael Bayer (@zzzeek) wrote: patch to play with |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: another patch to play with |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: i can get this series to work but not without doing things that break some of the traversal tests. will have to find some more time to look. |
Michael Bayer (@zzzeek) wrote: proposed change is at https://gerrit.sqlalchemy.org/#/c/146/. This is not a quick one and really changes things dramatically, though hopefully I can get it all to be limited to just downgrades which is not as critical of a use case. I'm hoping you've worked around your issue downstream in some way as this might take a few weeks for me to get enough time. |
cloew (@cloew) wrote: Thanks for the quick response! And ya, I think I've got a couple of things to try to make it not an issue for the time being. I was a little surprised at the solution. I was thinking the problem was the 642c version not being flagged for deletion. When I was tinkering with this yesterday, I got a patch that fixed the problem for me just by fixing the above and it seemed to put the alembic_version table in the proper state.
Sorry if I'm misunderstanding things and thanks for your time and awesome libraries! |
Michael Bayer (@zzzeek) wrote: I think you're understanding just fine, Im the one who can't keep this system in my head, I just went through trying a whole new branch yesterday which possibly gets closer to fixing this but that one also has problems. I've decided against changing how rows are related to versions in the alembic_versions table, for example - anytime a particular number is in there, everything that's dependent on it is implied and we should keep that consistent. Certainly the "unmerge branch" thing is part of what needs to be opened up here and my more recent patch has that too. Hopefully I'll be able to put up something new today. |
Michael Bayer (@zzzeek) wrote: OK, now I understand the problem, but due to all the work I did there is the actual resolution to this, then there's a new feature that is actually separate. So the actual bug is that, we're on 68f and 642 as heads. We tell the system, let's go to 15ac. The revision traversal thing works with this, and in current release calculates that the revisions we want to deal with are just those three, 68f, 642, 15ac. It does not include 636 (so technically, we only need to deal with 642 and 15ac, and not 68f at all, but that's not where the actual failure comes from here). The alembic_version updater (migration.py) sees that for us to go from 642 to 15ac, that's in its (incorrect) view a "merge point", e.g. where multiple revisions come together as one - in this case it sees 642 as a merge between 636 and 15ac. When really, it's not, 636 is not a version, it's a version with a "dependency" on 642 - which is a concept that was added on top of the original branching logic. The hackish addition of "dependency" as a modified notion of a revision with multiple bases is where this kind of mismatch starts. So what has to happen is that where we check that "hey this is a mergepoint to be unmerged", we look at the list of revs we're dealing with and see that hey, half of our mergepoint isn't here, so we really can't unmerge, we just need to delete. A patch against master (current 0.8.6 or as of master ccf3ca5) that fixes this is:
and that's it. But we can also address, and perhaps this should be a separate commit, and maybe even where we move from 0.8.7 to 0.9 (leaning towards just a separate commit, downgrades are not as super critical here), is that we can get the downgrade to not even bother downgrading 68f in this case, because our target is 15ac, so 68f can still remain. A small tweak to the revision mechanics allows for that. It also reveals a kind of bug in the display of current. In current 0.8.6, if we upgrade from base to 68f, it applies through 15ac. But if we do "alembic current", it only shows 68f. It doesn't show "15ac", even though this is a head, because of the dependency. So the current gerrit has changes for these things too. |
cloew (@cloew) wrote: Awesome! That patch fixed everything we needed. Not downgrading 68f seems like a really good idea. Thanks again for the quick fix/feedback/awesomeness! |
Michael Bayer (@zzzeek) wrote: Detect downgrades over dependencies distinctly from unmerge Previously, a downgrade to a version that is also a dependency Also change the string display of a version so that we don't Fixes: #377 → 111b1c1 |
Changes by Michael Bayer (@zzzeek):
|
Migrated issue, originally created by cloew (@cloew)
When implementing a migration schema via Branch Dependencies, you can get into a position where downgrading is impossible.
The culprit seems to be that any migration with more than 1 dependency is treated as a merge, but it is possible that all the dependencies are actually required by other heads. This causes the unmerge to break because it cannot find a revision to move the head for the current revision's branch to.
Attached is a simple set of Alembic migrations that result in the mentioned error
Attachments: patch2.txt | alembic-test.zip | patch.txt
The text was updated successfully, but these errors were encountered: