]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
fix AlterColumnOp modify_name ignorance
authorel <23kaplun@gmail.com>
Fri, 28 Mar 2025 13:22:29 +0000 (09:22 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Mar 2025 13:23:22 +0000 (09:23 -0400)
Fixed issue where the "modified_name" of :class:`.AlterColumnOp` would not
be considered when rendering op directives for autogenerate. While
autogenerate cannot detect changes in column name, this would nonetheless
impact approaches that made use of this attribute in rewriter recipes. Pull
request courtesy lenvk.

Fixes: #1635
Closes: #1636
Pull-request: https://github.com/sqlalchemy/alembic/pull/1636
Pull-request-sha: dd103354dcf9cd8db30c66a9a4d3879e4f1c5499

Change-Id: I3e4976a3e703ecd8d69ec208b2d225a8bf6a8251

alembic/autogenerate/render.py
docs/build/unreleased/1635.rst [new file with mode: 0644]
tests/test_autogen_render.py

index 50c51fa9304a13b038c24397c112efbec3167058..ffc277db81d174333d0f8892d28e464343ebcc37 100644 (file)
@@ -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/docs/build/unreleased/1635.rst b/docs/build/unreleased/1635.rst
new file mode 100644 (file)
index 0000000..2c95146
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, autogenerate
+    :tickets: 1635
+
+    Fixed issue where the "modified_name" of :class:`.AlterColumnOp` would not
+    be considered when rendering op directives for autogenerate. While
+    autogenerate cannot detect changes in column name, this would nonetheless
+    impact approaches that made use of this attribute in rewriter recipes. Pull
+    request courtesy lenvk.
index 600e57834fdf07d89479c774228f21aad6af2544..ed31183e8c0a2242c0dec692f751ccb3e72e3623 100644 (file)
@@ -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",