Is AlterColumnOp.modify_name ignored? #1632
-
Hello! I suspect there is a bug, but I'm not completely sure that it's not "by design" - would be nice if you could take a look. Context:
We found this rewriter feature https://alembic.sqlalchemy.org/en/latest/api/autogenerate.html#fine-grained-autogenerate-generation-with-rewriters
but when we delete a field from model and run I have a strong feeling that it's connected to this refactoring 10 years ago If my suspicions are naive, I can try to make a reproducable example, but for now it seems to be redundant :D Is it possible that I'm doing smth wrong? upd: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
hi - I think this is a bug that has always been there, because you're looking at the output of render.py -> _alter_column(), and if you look in that function, it isn't even looking at if you want to open an issue and PR here's a patch diff --git a/alembic/autogenerate/render.py b/alembic/autogenerate/render.py
index 50c51fa..ffc277d 100644
--- a/alembic/autogenerate/render.py
+++ b/alembic/autogenerate/render.py
@@ -505,6 +505,7 @@ def _alter_column(
type_ = op.modify_type
nullable = op.modify_nullable
comment = op.modify_comment
+ newname = op.modify_name
autoincrement = op.kw.get("autoincrement", None)
existing_type = op.existing_type
existing_nullable = op.existing_nullable
@@ -533,6 +534,8 @@ def _alter_column(
rendered = _render_server_default(server_default, autogen_context)
text += ",\n%sserver_default=%s" % (indent, rendered)
+ if newname is not None:
+ text += ",\n%snew_column_name=%r" % (indent, newname)
if type_ is not None:
text += ",\n%stype_=%s" % (indent, _repr_type(type_, autogen_context))
if nullable is not None:
diff --git a/tests/test_autogen_render.py b/tests/test_autogen_render.py
index 600e578..ed31183 100644
--- a/tests/test_autogen_render.py
+++ b/tests/test_autogen_render.py
@@ -1327,6 +1327,18 @@ class AutogenRenderTest(TestBase):
{"from mypackage import MySpecialType"},
)
+ def test_render_modify_name(self):
+ op_obj = ops.AlterColumnOp(
+ "sometable",
+ "somecolumn",
+ modify_name="newcolumnname",
+ )
+ eq_ignore_whitespace(
+ autogenerate.render_op_text(self.autogen_context, op_obj),
+ "op.alter_column('sometable', 'somecolumn', "
+ "new_column_name='newcolumnname')",
+ )
+
def test_render_modify_type(self):
op_obj = ops.AlterColumnOp(
"sometable",
|
Beta Was this translation helpful? Give feedback.
hi -
I think this is a bug that has always been there, because you're looking at the output of render.py -> _alter_column(), and if you look in that function, it isn't even looking at
modify_name
at all, nor is it looking in that older version etiher.if you want to open an issue and PR here's a patch