Skip to content

AttributeError: 'BatchOperationsImpl' object has no attribute 'drop_table_comment' #799

@CompPhy

Description

@CompPhy

Describe the bug
We are using "render_as_batch=True" in our context.configure block; then using "alembic revision --autogenerate" to generate our updated version file. The version file contains "batch_op.drop_table_comment()" and fails with the exception below. It looks like batch operations just don't support drop_table_comment, but autogenerate is unaware of this fact.

As a work around, we are just going to remove the drop_table_comment line for now. It is irrelevant at the moment.

Expected behavior
I think the best option here would be to make BatchOperationsImpl aware of drop_table_comment. Looking at the code for BatchOperationsImpl, it looks like "create_column_comment" is there but not "drop_table_comment".

To Reproduce

with op.batch_alter_table('InsertTableName', schema=None) as batch_op:
    batch_op.drop_table_comment('InsertTableName', existing_comment='InsertCommentHere', schema=None)

Error

Traceback (most recent call last):
  File "/home/kshutt/mandate/bin/alembic", line 8, in <module>
    sys.exit(main())
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/config.py", line 559, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/config.py", line 553, in main
    self.run_cmd(cfg, options)
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/config.py", line 533, in run_cmd
    **dict((k, getattr(options, k, None)) for k in kwarg)
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/command.py", line 294, in upgrade
    script.run_env()
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/script/base.py", line 481, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/util/pyfiles.py", line 97, in load_python_file
    module = load_module_py(module_id, path)
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/util/compat.py", line 217, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "alembic/env.py", line 267, in <module>
    run_migrations_online()
  File "alembic/env.py", line 243, in run_migrations_online
    context.run_migrations(engine_name=name)
  File "<string>", line 8, in run_migrations
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/runtime/environment.py", line 813, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/runtime/migration.py", line 560, in run_migrations
    step.migration_fn(**kw)
  File "/home/kshutt/cofe/database/migrations/WineDirect/alembic/versions/497fe4469833_.py", line 22, in upgrade
    globals()["upgrade_%s" % engine_name]()
  File "/home/kshutt/cofe/database/migrations/WineDirect/alembic/versions/497fe4469833_.py", line 1804, in upgrade_WD_ECOM
    schema=None
  File "<string>", line 3, in drop_table_comment
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/operations/ops.py", line 1310, in drop_table_comment
    return operations.invoke(op)
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/operations/base.py", line 354, in invoke
    return fn(self, operation)
  File "/home/kshutt/mandate/lib/python2.7/site-packages/alembic/operations/toimpl.py", line 120, in drop_table_comment
    operations.impl.drop_table_comment(table)
AttributeError: 'BatchOperationsImpl' object has no attribute 'drop_table_comment'

Versions.

  • OS: CentOS Linux release 7.9.2009 (all patches applied up to 1/27/2021)
  • Python: 2.7.5
  • Alembic: 1.5.5
  • SQLAlchemy: 1.3.23
  • Database: mysql Ver 14.14 Distrib 5.7.32-35, for Linux (x86_64) using 6.2
  • DBAPI: mysqlclient 1.4.6, MySQL-python 1.2.5

Additional context

Have a nice day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions