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)" % {
--- /dev/null
+.. change::
+ :tags: bug, autogenerate
+ :tickets: 529
+
+ Fixed issue in new comment support where autogenerated Python code
+ for comments wasn't using ``repr()`` thus causing issues with
+ quoting. Pull request courtesy Damien Garaud.
"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)