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

dupe entries in alembic_versions can break revision logic #314

Closed
sqlalchemy-bot opened this Issue Aug 3, 2015 · 3 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Aug 3, 2015

Migrated issue, originally created by Michael Bayer (@zzzeek)

e.g.

#!


sqlite> select * from alembic_version;
32f69b44319
32f69b44319

this should raise an error on the stamp, but versioning fails:

#!


Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/classic/tmp/alembic_0_7_7/alembic/config.py", line 442, in <module>
    main()
  File "/Users/classic/tmp/alembic_0_7_7/alembic/config.py", line 439, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/Users/classic/tmp/alembic_0_7_7/alembic/config.py", line 433, in main
    self.run_cmd(cfg, options)
  File "/Users/classic/tmp/alembic_0_7_7/alembic/config.py", line 416, in run_cmd
    **dict((k, getattr(options, k)) for k in kwarg)
  File "/Users/classic/tmp/alembic_0_7_7/alembic/command.py", line 193, in downgrade
    script.run_env()
  File "/Users/classic/tmp/alembic_0_7_7/alembic/script.py", line 390, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/Users/classic/tmp/alembic_0_7_7/alembic/util.py", line 244, in load_python_file
    module = load_module_py(module_id, path)
  File "/Users/classic/tmp/alembic_0_7_7/alembic/compat.py", line 68, in load_module_py
    module_id, path).load_module(module_id)
  File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1614, in load_module
  File "<frozen importlib._bootstrap>", line 596, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "foo/env.py", line 70, in <module>
    run_migrations_online()
  File "foo/env.py", line 65, in run_migrations_online
    context.run_migrations()
  File "<string>", line 7, in run_migrations
  File "/Users/classic/tmp/alembic_0_7_7/alembic/environment.py", line 738, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Users/classic/tmp/alembic_0_7_7/alembic/migration.py", line 302, in run_migrations
    for step in self._migrations_fn(heads, self):
  File "/Users/classic/tmp/alembic_0_7_7/alembic/command.py", line 182, in downgrade
    return script._downgrade_revs(revision, rev)
  File "/Users/classic/tmp/alembic_0_7_7/alembic/script.py", line 315, in _downgrade_revs
    current_rev, destination)
  File "/Users/classic/tmp/alembic_0_7_7/alembic/revision.py", line 512, in iterate_revisions
    inclusive, assert_relative_length
  File "/Users/classic/tmp/alembic_0_7_7/alembic/revision.py", line 450, in _relative_iterate
    inclusive=inclusive, implicit_base=implicit_base))
  File "/Users/classic/tmp/alembic_0_7_7/alembic/revision.py", line 672, in _iterate_revisions
    total_space.remove(rev.revision)
KeyError: '32f69b44319'

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Aug 3, 2015

Michael Bayer (@zzzeek) wrote:

if we have an 0.7.8, then backport. otherwise keep it in 0.8.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Aug 3, 2015

Michael Bayer (@zzzeek) wrote:

  • Fixed bug where in the erroneous case that alembic_version contains
    duplicate revisions, some commands would fail to process the
    version history correctly and end up with a KeyError. The fix
    allows the versioning logic to proceed, however a clear error is
    emitted later when attempting to update the alembic_version table.
    fixes #314

e155fa6

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Aug 3, 2015

Changes by Michael Bayer (@zzzeek):

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