return templ.format(
prefix=_alembic_autogenerate_prefix(autogen_context),
tname=op.table_name,
- comment="'%s'" % op.comment if op.comment is not None else None,
- existing="'%s'" % op.existing_comment
+ comment="%r" % op.comment if op.comment is not None else None,
+ existing="%r" % op.existing_comment
if op.existing_comment is not None
else None,
schema="'%s'" % op.schema if op.schema is not None else None,
return templ.format(
prefix=_alembic_autogenerate_prefix(autogen_context),
tname=op.table_name,
- existing="'%s'" % op.existing_comment
+ existing="%r" % op.existing_comment
if op.existing_comment is not None
else None,
schema="'%s'" % op.schema if op.schema is not None else None,
--- /dev/null
+.. change::
+ :tags: bug, autogenerate
+ :tickets: 549
+
+ Fixed bug where rendering of comment text for table-level comments within
+ :meth:`.Operations.create_table_comment` and
+ :meth:`.Operations.drop_table_comment` was not properly quote-escaped
+ within rendered Python code for autogenerate.
")",
)
+ @config.requirements.comments_api
+ def test_render_create_table_comment_with_quote_op(self):
+ op_obj = ops.CreateTableCommentOp(
+ "table_name",
+ "This is john's comment",
+ existing_comment='This was john\'s "comment"',
+ )
+ eq_ignore_whitespace(
+ autogenerate.render_op_text(self.autogen_context, op_obj),
+ "op.create_table_comment("
+ " 'table_name',"
+ ' "This is john\'s comment",'
+ " existing_comment='This was john\\'s \"comment\"',"
+ " schema=None"
+ ")",
+ )
+
def test_render_create_table_comment_op_with_existing_comment(self):
op_obj = ops.CreateTableCommentOp(
"table_name", "comment", existing_comment="old comment"
")",
)
+ def test_render_drop_table_comment_op_existing_with_quote(self):
+ op_obj = ops.DropTableCommentOp(
+ "table_name", existing_comment="This was john's comment"
+ )
+ eq_ignore_whitespace(
+ autogenerate.render_op_text(self.autogen_context, op_obj),
+ "op.drop_table_comment("
+ " 'table_name',"
+ ' existing_comment="This was john\'s comment",'
+ " schema=None"
+ ")",
+ )
+
class RenderNamingConventionTest(TestBase):
def setUp(self):