kvesteri / postgresql-audit

Audit trigger for PostgreSQL
BSD 2-Clause "Simplified" License
126 stars 28 forks source link

Error running flask db migrate #60

Open coreystokes-8451 opened 2 years ago

coreystokes-8451 commented 2 years ago

Hello, trying to use this library and get the following error when running 'flask db migrate':


Traceback (most recent call last):
  File "/Users/c501854/azure/aston/venv/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/Users/c501854/azure/aston/venv/lib/python3.9/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 "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/flask/cli.py", line 426, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/flask_migrate/cli.py", line 89, in migrate
    _migrate(directory, message, sql, head, splice, branch_label, version_path,
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/flask_migrate/__init__.py", line 95, in wrapped
    f(*args, **kwargs)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/flask_migrate/__init__.py", line 213, in migrate
    command.revision(config, message, autogenerate=True, sql=sql,
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/command.py", line 227, in revision
    script_directory.run_env()
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/script/base.py", line 563, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 92, in load_python_file
    module = load_module_py(module_id, path)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 108, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "migrations/env.py", line 96, in <module>
    run_migrations_online()
  File "migrations/env.py", line 90, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/runtime/environment.py", line 851, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/runtime/migration.py", line 608, in run_migrations
    for step in self._migrations_fn(heads, self):
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/command.py", line 203, in retrieve_migrations
    revision_context.run_autogenerate(rev, context)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/autogenerate/api.py", line 520, in run_autogenerate
    self._run_environment(rev, migration_context, True)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/autogenerate/api.py", line 567, in _run_environment
    compare._populate_migration_script(
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/autogenerate/compare.py", line 54, in _populate_migration_script
    upgrade_ops.reverse_into(downgrade_ops)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/operations/ops.py", line 2482, in reverse_into
    reversed([op.reverse() for op in self.ops])
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/operations/ops.py", line 2482, in <listcomp>
    reversed([op.reverse() for op in self.ops])
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/operations/ops.py", line 1126, in reverse
    self.to_table(), _namespace_metadata=self._namespace_metadata
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/operations/ops.py", line 1162, in to_table
    return schema_obj.table(
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/operations/schemaobj.py", line 216, in table
    constraints = [
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/operations/schemaobj.py", line 217, in <listcomp>
    sqla_compat._copy(elem, target_table=t)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/alembic/util/sqla_compat.py", line 136, in _copy
    return schema_item._copy(**kw)
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/ext.py", line 248, in _copy
    elements = [
  File "/Users/c501854/azure/aston/venv/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/ext.py", line 251, in <listcomp>
    self.operators[expr.name],
KeyError: 'native_transaction_id'

I am using Python 3.9

gmassman commented 9 months ago

I'm seeing the same issue using python 3.11 and sqlalchemy 1.4.50.

psudol-tw commented 9 months ago

I am seeing the same issue with python 3.10.12 and sqlalchemy 1.4.44.

gmassman commented 7 months ago

I ended up forking this library and modifying it extensively to work with flask-sqlalchemy/flask-migrate. Might be useful for others who find this thread.

https://github.com/gmassman/flask-audit-logger