it's likely a bug.   It looks like you've done some investigation
already.    I don't offhand have any understanding of the issue
either, I would need to build up a reproduction case and then stare at
it for several hours to figure out what's happening.    So first step
is if you can make a bug report at
https://bitbucket.org/zzzeek/alembic/issues?status=new&status=open.
Creating a test case is elaborate here, the graph you have above is
likely enough to get started.    The next step, which I can do, or you
are welcome to work on if you have the motivation, is to create a test
of this case in tests/test_version_traversal.py, similar to a test
like this one: 
https://bitbucket.org/zzzeek/alembic/src/b702e057aeaa640c03232c77405dc5415ac8a670/tests/test_version_traversal.py#lines-557

these bugs are often hard to fix, so I would need to find some time to
work on it.  if you have a workaround for now that would be good.



On Mon, May 28, 2018 at 11:13 AM, Lucas Kahlert <lucas.kahl...@gmail.com> wrote:
> Hallo,
>
> we are using Alembic in a rather big project with various database revisions
> and stumbled over a problem with diamond-shaped branch-merges.
>
> We have the following diamond-shaped dependency tree with three branches:
>
> "master" Branch
> "addon 1" branch
> "addon 2" branch
>
> The graph looks as follows:
>
>   |    |    |
>   |    a    |
>   |  . | .  |
>   | .  |  . |
>   |.   |   .|
>   x1   |   y1
>   |.   |   .|
>   | .  |  . |
>   |  . | .  |
>   |    b    |
>   |    |    |
>   |    |    |
>   x2   c    y2
>
> Straight lines represent down_revision and dotted lines mean depends_on
> relationships. The addon branches should not be merged into the master
> branch. Hence, we use the depends_on directive as described in the Alembic
> docs Branch Dependencies.We have various constructs of this shape in our
> dependency graph.
>
> If we run alembic upgrade heads, we get an KeyError when applying the
> "Merge" migration:
>
>   File "/home/lucas/dev/torql/api/torql/migrations/env.py", line 115, in
> <module>
>     run_migrations_online()
>   File "/home/lucas/dev/torql/api/torql/migrations/env.py", line 109, in
> run_migrations_online
>     context.run_migrations()
>   File "<string>", line 8, in run_migrations
>   File
> "/home/lucas/dev/torql/.venv/lib/python3.6/site-packages/alembic/runtime/environment.py",
> line 797, in run_migrations
>     self.get_context().run_migrations(**kw)
>   File
> "/home/lucas/dev/torql/.venv/lib/python3.6/site-packages/alembic/runtime/migration.py",
> line 319, in run_migrations
>     head_maintainer.update_to_step(step)
>   File
> "/home/lucas/dev/torql/.venv/lib/python3.6/site-packages/alembic/runtime/migration.py",
> line 486, in update_to_step
>     self._delete_version(delrev)
>   File
> "/home/lucas/dev/torql/.venv/lib/python3.6/site-packages/alembic/runtime/migration.py",
> line 437, in _delete_version
>     self.heads.remove(version)
> KeyError: 'a'
>
> Alembic cannot delete the branchpoint revision because it is not included in
> the heads set of the alembic.runtime.migration.HeadMaintainer instance.
>
> The problem can be solved by inserting a "Noop" revision between the Branch-
> and Mergepoint:
>
>   |    |    |
>   |    a    |
>   |  . | .  |
>   | .  |  . |
>   |.   |   .|
>   x1  noop  y1
>   |.   |   .|
>   | .  |  . |
>   |  . | .  |
>   |    b    |
>   |    |    |
>   |    |    |
>   x2   c    y2
>
> Can someone explain the problem to us or is this a bug in Alembic?
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy-alembic" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy-alembic+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to