-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
Cases where a revision dependency graph contains a loop or cycle. #757
Comments
sounds fine to me
seems fine
if you can establish this behavior for me I'm all for it. the branch logic is really complicated and simplifying it would be great if you have cycles to spare. test cases for new behaviors / error messages / etc. would be in https://github.com/sqlalchemy/alembic/blob/master/tests/test_revision.py most likely.
if you have dev cycles to spare for a working PR, I'd love to review it. |
Koichiro Den has proposed a fix for this issue in the master branch: Raise an exception if any loop or cycle found in a revision graph constructed. https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/2379 |
looked at some of the cycles. the logic that I wrote, which I continue to find pretty hard to work with, is at https://github.com/sqlalchemy/alembic/blob/master/alembic/script/revision.py#L750 . apparently it will iterate revision graphs with cycles without raising anyhting, it just gives you an invalid traversal (this is without your patch that prevents such a tree from existing):
I thought at first we'd be raising the cycle errors inside of _iterate_revisions, rather than as a separate sanity check. ultimately it doesnt matter i was just hoping that someone could make that logic followable. |
I think it's fine if we notice the cycle at startup time. alembic is set for version 1.5 where we are making some bigger changes like dropping old SQLAlcehmy version support and some adjustments to the transaction model for SQLAlhcemy 1.4 so if a set of revisions has a cycle, detecting it up front is fine, at worst we could make it just a warning and not an error but I think as an error is OK. |
All right, thanks for your quick response! |
from start to finish I'm very impressed! please feel free to contribute to SQLAlchemy / Alembic any time. as published elsewhere the developer community hangs out on https://gitter.im/sqlalchemy/devel . |
Glad to hear that, thanks for your patience and cooperation! |
How to effectively then remove the cycle? |
Preface
script_location
may contain one or more connected dependency graphs but let us focus on just one of them for simplicity's sake.when it's a strongly-connected graph, (see Cases where a revision dependency graph contains a loop or cycle. #757 (comment))revision
anddown_revision
to the same value, which is notNone
. Also let this contain the case where there is just one revision with a self-loop.when it's a unilaterally-connected graph, (see Cases where a revision dependency graph contains a loop or cycle. #757 (comment))From an admin point of view, (a) looks like just being ignored because iterating through all revisions (e.g.,
alembic branches
) does not start in the first place. This is because "heads" must be empty after_revision_map
discards all reachable revisions.On the other hand, (b) raises
revision.RangeNotAncestorError
when an admin tries to do the same traversal because in this case "bases" must have been empty while "heads" is kept undiscarded.Question
IMHO, such different behaviours for (a) and (b) are confusing. It would be better if
Any thoughts?
The text was updated successfully, but these errors were encountered: