Python3 error when running alembic upgrade head

718 views
Skip to first unread message

Marco Falcioni

unread,
Apr 4, 2016, 1:59:23 PM4/4/16
to sqlalchemy-alembic
Hello,
we are moving to python3 and we ran into the error - is there anything we should do differently?
Thanks
Marco

(alembic==0.8.5)

INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Traceback (most recent call last):
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/revision.py", line 349, in _revision_for_ident
    revision = self._revision_map[resolved_id]
KeyError: 52

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/joe/venv/test_py3/bin/alembic", line 11, in <module>
    sys.exit(main())
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/config.py", line 479, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/config.py", line 473, in main
    self.run_cmd(cfg, options)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/config.py", line 456, in run_cmd
    **dict((k, getattr(options, k)) for k in kwarg)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/command.py", line 174, in upgrade
    script.run_env()
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/base.py", line 397, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/util/pyfiles.py", line 81, in load_python_file
    module = load_module_py(module_id, path)
  File "_py3/lib/python3.5/site-packages/alembic/util/compat.py", line 68, in load_module_py
    module_id, path).load_module(module_id)
  File "<frozen importlib._bootstrap_external>", line 385, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 806, in load_module
  File "<frozen importlib._bootstrap_external>", line 665, in load_module
  File "<frozen importlib._bootstrap>", line 268, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "legacy_schema/env.py", line 70, in <module>
    run_migrations_online()
  File "legacy_schema/env.py", line 63, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/runtime/environment.py", line 797, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/runtime/migration.py", line 303, in run_migrations
    for step in self._migrations_fn(heads, self):
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/command.py", line 163, in upgrade
    return script._upgrade_revs(revision, rev)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/base.py", line 310, in _upgrade_revs
    revs = list(revs)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/revision.py", line 610, in _iterate_revisions
    requested_lowers = self.get_revisions(lower)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/revision.py", line 299, in get_revisions
    return sum([self.get_revisions(id_elem) for id_elem in id_], ())
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/revision.py", line 299, in <listcomp>
    return sum([self.get_revisions(id_elem) for id_elem in id_], ())
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/revision.py", line 304, in get_revisions
    for rev_id in resolved_id)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/revision.py", line 304, in <genexpr>
    for rev_id in resolved_id)
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/revision.py", line 352, in _revision_for_ident
    revs = [x for x in self._revision_map
  File "/Users/joe/venv/test_py3/lib/python3.5/site-packages/alembic/script/revision.py", line 353, in <listcomp>
    if x and x.startswith(resolved_id)]
TypeError: startswith first arg must be str or a tuple of str, not int

Mike Bayer

unread,
Apr 4, 2016, 2:12:22 PM4/4/16
to sqlalchem...@googlegroups.com
do you have any integer values inside your version files for the value
of "down_revision", "revision", "branch_labels", or "depends_on"? that
would be the problem. Those must be strings.
> --
> 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-alem...@googlegroups.com
> <mailto:sqlalchemy-alem...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Marco

unread,
Apr 4, 2016, 2:36:04 PM4/4/16
to sqlalchem...@googlegroups.com
Hi Mike,
that put us on the right track - the reason was a stray "use_unicode=0" in the connection string as we are migrating from py2 to py3. The value in the alembic_version version_num was being returned as byte, which the code was interpreting as a tuple of integer values.
Thanks for the quick response!
Cheers
Marco


You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy-alembic/taexgkxxkKY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy-alem...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages