Navigation Menu

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

Unable to change column comment with Alembic #191

Closed
eeshugerman opened this issue Feb 6, 2020 · 7 comments
Closed

Unable to change column comment with Alembic #191

eeshugerman opened this issue Feb 6, 2020 · 7 comments

Comments

@eeshugerman
Copy link
Contributor

eeshugerman commented Feb 6, 2020

We're using sqlalchemy-redshift with Alembic, and have found that we are unable to add or change comments on columns. Creating a new column with a comment works fine though.

Let me know if there's any more information I can provide, or if I should open this issue with SQLAlchemy or Alembic.

from alembic import op

op.alter_column(
    'some_table',
    'some_column',
    comment='my column comment',
)
sqlalchemy.exc.CompileError: <class 'alembic.ddl.base.ColumnComment'> construct has no default compilation handler.
click for full traceback
Traceback (most recent call last):
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 88, in _compiler_dispatch
    meth = getter(visitor)
AttributeError: 'RedshiftDDLCompiler' object has no attribute 'visit_clause'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/ext/compiler.py", line 423, in _wrap_existing_dispatch
    return existing_dispatch(element, compiler, **kw)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py", line 90, in _compiler_dispatch
    raise exc.UnsupportedCompilationError(visitor, cls)
sqlalchemy.exc.UnsupportedCompilationError: Compiler <sqlalchemy_redshift.dialect.RedshiftDDLCompiler object at 0x7f2436379a20> can't render element of type <class 'sqlalchemy.sql.elements.ClauseElement'> (Background on this error at: http://sqlalche.me/e/l7de)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/elliott/.virtualenvs/dwp/bin/alembic", line 10, in <module>
    sys.exit(main())
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/config.py", line 573, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/config.py", line 567, in main
    self.run_cmd(cfg, options)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/config.py", line 547, in run_cmd
    **dict((k, getattr(options, k, None)) for k in kwarg)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/command.py", line 298, in upgrade
    script.run_env()
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/script/base.py", line 489, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
    module = load_module_py(module_id, path)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/util/compat.py", line 173, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "alembic/env.py", line 152, in <module>
    run_migrations_online()
  File "alembic/env.py", line 146, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/runtime/environment.py", line 846, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/runtime/migration.py", line 518, in run_migrations
    step.migration_fn(**kw)
  File "/home/elliott/dwp/arthur/ltbd/alembic/versions/2020-02-06_60f608383d18_column_comment_test.py", line 24, in upgrade
    comment="test comment",
  File "<string>", line 8, in alter_column
  File "<string>", line 3, in alter_column
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/operations/ops.py", line 1777, in alter_column
    return operations.invoke(alt)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/operations/base.py", line 345, in invoke
    return fn(self, operation)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/operations/toimpl.py", line 56, in alter_column
    **operation.kw
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/ddl/postgresql.py", line 140, in alter_column
    **kw
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/ddl/impl.py", line 212, in alter_column
    existing_comment=existing_comment,
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/alembic/ddl/impl.py", line 134, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 988, in execute
    return meth(self, multiparams, params)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1043, in _execute_ddl
    else None,
  File "<string>", line 1, in <lambda>
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 462, in compile
    return self._compiler(dialect, bind=bind, **kw)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 29, in _compiler
    return dialect.ddl_compiler(dialect, self, **kw)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 319, in __init__
    self.string = self.process(self.statement, **compile_kwargs)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py", line 350, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/ext/compiler.py", line 436, in <lambda>
    lambda *arg, **kw: existing(*arg, **kw),
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/ext/compiler.py", line 478, in __call__
    return fn(element, compiler, **kw)
  File "/home/elliott/.virtualenvs/dwp/lib/python3.6/site-packages/sqlalchemy/ext/compiler.py", line 427, in _wrap_existing_dispatch
    "compilation handler." % type(element)
sqlalchemy.exc.CompileError: <class 'alembic.ddl.base.ColumnComment'> construct has no default compilation handler.
@jklukas
Copy link
Member

jklukas commented Feb 7, 2020

I don't know whether this is a problem at the SQLAlchemy level, Alembic level, or with this dialect.

Neither of the maintainers (me and @graingert) are active users of the project anymore, so we aren't likely to be able to spend time investigating further. If you're able to identify the problem, though, a PR would be welcome and I'll try to prioritize reviewing and merging.

@eeshugerman
Copy link
Contributor Author

@zzzeek, any insight?

@zzzeek
Copy link

zzzeek commented Feb 7, 2020

sure, you need to add the ColumnComment element in the same way RenameTable is supported here: https://github.com/sqlalchemy-redshift/sqlalchemy-redshift/blob/master/sqlalchemy_redshift/dialect.py#L33 . I see a few other PG-specific elements that may or may not apply to redshift as well.

    from alembic.ddl.base import ColumnComment
    compiles(ColumnComment, 'redshift')(postgresql.visit_column_comment)

@jklukas is sqlalchemy-redshift still maintained?

@jklukas
Copy link
Member

jklukas commented Feb 7, 2020

@jklukas is sqlalchemy-redshift still maintained?

It's mostly just me at this point and I am not actively making improvements. I review and merge PRs and make new releases, but I'm not investing any time in directing the project or anticipating new needs.

Probably the right thing to do at this point is to advertise for new maintainers and see if there is anybody willing to be more active.

@eeshugerman
Copy link
Contributor Author

Thanks @zzzeek! @jklukas I'll open a PR when I have a chance.

@eeshugerman
Copy link
Contributor Author

Finally had a chance to come back to this. PR: #198

@jklukas
Copy link
Member

jklukas commented May 5, 2020

Merged. Thanks for putting this together, @eeshugerman

@jklukas jklukas closed this as completed May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants