Skip to content
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

Need an option to see the Alembic stack strace #434

Closed
woopla opened this issue Sep 14, 2021 · 3 comments
Closed

Need an option to see the Alembic stack strace #434

woopla opened this issue Sep 14, 2021 · 3 comments
Labels

Comments

@woopla
Copy link

woopla commented Sep 14, 2021

Hello,

We're having an issue generating migrations through flask db migrate, with a fairly sparse error message :D

flask db migrate -m "Fix Filename join issue"
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.

This returns with an exit code 1.

The stack trace is hidden by the catch_errors() function defined and used in __init.py__. When I remove the wrapper, I get the much more useful:

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
Traceback (most recent call last):
  File "/usr/local/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 967, in main
    cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
  File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 426, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flask_migrate/cli.py", line 104, in migrate
    _migrate(directory, message, sql, head, splice, branch_label, version_path,
  File "/usr/local/lib/python3.8/site-packages/flask_migrate/__init__.py", line 97, in wrapped
    f(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flask_migrate/__init__.py", line 161, in migrate
    command.revision(config, message, autogenerate=True, sql=sql,
  File "/usr/local/lib/python3.8/site-packages/alembic/command.py", line 212, in revision
    script_directory.run_env()
  File "/usr/local/lib/python3.8/site-packages/alembic/script/base.py", line 490, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/usr/local/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 97, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/local/lib/python3.8/site-packages/alembic/util/compat.py", line 184, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "migrations/env.py", line 110, in <module>
    run_migrations_online()
  File "migrations/env.py", line 104, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/local/lib/python3.8/site-packages/alembic/runtime/environment.py", line 813, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/usr/local/lib/python3.8/site-packages/alembic/runtime/migration.py", line 549, in run_migrations
    for step in self._migrations_fn(heads, self):
  File "/usr/local/lib/python3.8/site-packages/alembic/command.py", line 188, in retrieve_migrations
    revision_context.run_autogenerate(rev, context)
  File "/usr/local/lib/python3.8/site-packages/alembic/autogenerate/api.py", line 462, in run_autogenerate
    self._run_environment(rev, migration_context, True)
  File "/usr/local/lib/python3.8/site-packages/alembic/autogenerate/api.py", line 476, in _run_environment
    raise util.CommandError("Target database is not up to date.")
alembic.util.exc.CommandError: Target database is not up to date.

Could you please add an option to disable the wrapping?

Thanks,

Clément

@miguelgrinberg
Copy link
Owner

The catch_errors decorator suppresses the stack trace, but you can see in the code that it writes the error message to the log. I suspect your logging configuration is incorrect, and for that reason you do not see the error message in the output of the command.

Compare the alembic.ini file from this repository against the version that you have in your migrations folder and apply any changes you may be missing.

@emilija-omnisend
Copy link

emilija-omnisend commented Jun 3, 2022

Hello, I'm having the same problem. The alembic.ini.mako file matches and we see general info messages in the logs. But no errors unless I manually remove catch_errors, then I can see the stack trace.

@miguelgrinberg
Copy link
Owner

@emilija-omnisend Are you sure you have the latest alembic.ini in your repository? Because this is a well known issue that was fixed a while ago. Make sure you have flask_migrate declared as a logger:

[loggers]
keys = root,sqlalchemy,alembic,flask_migrate

And then that this logger is configured with the appropriate level:

[logger_flask_migrate]
level = INFO
handlers =
qualname = flask_migrate

I actually just tested this on an old project of mine. The error message did not display, but as soon as I updated alembic.ini I started seeing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants