]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Fix single quote escaping for the SQL comments 530/head
authorDamien Garaud <damien.garaud@oslandia.com>
Wed, 23 Jan 2019 14:38:34 +0000 (15:38 +0100)
committerDamien Garaud <damien.garaud@oslandia.com>
Wed, 23 Jan 2019 14:38:34 +0000 (15:38 +0100)
alembic/autogenerate/render.py
tests/test_autogen_render.py

index 64dbaebf00a579fc4bdf8c5a008d5505bcaec4ee..3fb0a422daa67860b47a4a3a129b923d2240a715 100644 (file)
@@ -614,7 +614,7 @@ def _render_column(column, autogen_context):
 
     comment = sqla_compat._comment_attribute(column)
     if comment:
-        opts.append(("comment", "'%s'" % comment))
+        opts.append(("comment", '%r' % comment))
 
     # TODO: for non-ascii colname, assign a "key"
     return "%(prefix)sColumn(%(name)r, %(type)s, %(kw)s)" % {
index 7673a493088c70e120d771375d14d58c7a391102..4d010a419f45059f5f7ad1723f8e9e8e01c00880 100644 (file)
@@ -1155,6 +1155,19 @@ class AutogenRenderTest(TestBase):
             "comment='This is a comment')",
         )
 
+    @config.requirements.comments_api
+    def test_render_col_comment_with_quote(self):
+        c = Column("some_key", Integer, comment="This is a john's comment")
+        Table("some_table", MetaData(), c)
+        result = autogenerate.render._render_column(c, self.autogen_context)
+        print(result)
+        eq_ignore_whitespace(
+            result,
+            "sa.Column('some_key', sa.Integer(), "
+            "nullable=True, "
+            "comment=\"This is a john's comment\")",
+        )
+
     def test_render_col_autoinc_false_mysql(self):
         c = Column("some_key", Integer, primary_key=True, autoincrement=False)
         Table("some_table", MetaData(), c)