Fixed issue where dialect-specific keyword arguments within the
:class:`.DropIndex` operation directive would not render in the
autogenerated Python code. As support was improved for adding dialect
specific arguments to directives as part of :ticket:`803`, in particular
arguments such as "postgresql_concurrently" which apply to the actual
create/drop of the index, support was needed for these to render even in a
drop index operation. Pull request courtesy Jet Zhou.
Fixes: #849
Closes: #852
Pull-request: https://github.com/sqlalchemy/alembic/pull/852
Pull-request-sha:
6392a287179ed746f709ba1e0e07ccab3ea8e4c6
Change-Id: I9b602178c32d6c6a41c0dbe0969a19bd4fa329bd
@renderers.dispatch_for(ops.DropIndexOp)
def _drop_index(autogen_context, op):
+ index = op.to_index()
+
has_batch = autogen_context._has_batch
if has_batch:
- tmpl = "%(prefix)sdrop_index(%(name)r)"
+ tmpl = "%(prefix)sdrop_index(%(name)r%(kwargs)s)"
else:
tmpl = (
"%(prefix)sdrop_index(%(name)r, "
- "table_name=%(table_name)r%(schema)s)"
+ "table_name=%(table_name)r%(schema)s%(kwargs)s)"
)
text = tmpl % {
"name": _render_gen_name(autogen_context, op.index_name),
"table_name": _ident(op.table_name),
"schema": ((", schema=%r" % _ident(op.schema)) if op.schema else ""),
+ "kwargs": (
+ ", "
+ + ", ".join(
+ [
+ "%s=%s"
+ % (key, _render_potential_expr(val, autogen_context))
+ for key, val in index.kwargs.items()
+ ]
+ )
+ )
+ if len(index.kwargs)
+ else "",
}
return text
--- /dev/null
+.. change::
+ :tags: bug, autogenerate
+ :tickets: 849
+
+ Fixed issue where dialect-specific keyword arguments within the
+ :class:`.DropIndex` operation directive would not render in the
+ autogenerated Python code. As support was improved for adding dialect
+ specific arguments to directives as part of :ticket:`803`, in particular
+ arguments such as "postgresql_concurrently" which apply to the actual
+ create/drop of the index, support was needed for these to render even in a
+ drop index operation. Pull request courtesy Jet Zhou.
"op.drop_index('test_active_code_idx', table_name='test')",
)
+ @testing.emits_warning("Can't validate argument ")
+ def test_render_drop_index_custom_kwarg(self):
+ t = Table(
+ "test",
+ MetaData(),
+ Column("id", Integer, primary_key=True),
+ Column("active", Boolean()),
+ Column("code", String(255)),
+ )
+ idx = Index(None, t.c.active, t.c.code, somedialect_foobar="option")
+ op_obj = ops.DropIndexOp.from_index(idx)
+ eq_ignore_whitespace(
+ autogenerate.render_op_text(self.autogen_context, op_obj),
+ "op.drop_index(op.f('ix_test_active'), table_name='test', "
+ "somedialect_foobar='option')",
+ )
+
def test_drop_index_batch(self):
"""
autogenerate.render._drop_index