From: Denis Kataev Date: Wed, 11 Apr 2018 14:27:34 +0000 (-0400) Subject: Use repr for drop_constraint schema X-Git-Tag: rel_0_9_10~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3657c79ac00bf4e3804de303f6718f36f3db0e32;p=thirdparty%2Fsqlalchemy%2Falembic.git Use repr for drop_constraint schema The "op.drop_constraint()" directive will now render using ``repr()`` for the schema name, in the same way that "schema" renders for all the other op directives. Pull request courtesy Denis Kataev. Change-Id: Ifbcabcfd87fc631ec12a488478851e7841275678 Pull-request: https://github.com/zzzeek/alembic/pull/44 --- diff --git a/alembic/autogenerate/render.py b/alembic/autogenerate/render.py index 0ba12dac..0459d7a6 100644 --- a/alembic/autogenerate/render.py +++ b/alembic/autogenerate/render.py @@ -275,7 +275,7 @@ def _drop_constraint(autogen_context, op): autogen_context, op.constraint_name), 'table_name': _ident(op.table_name), 'type': op.constraint_type, - 'schema': (", schema='%s'" % _ident(op.schema)) + 'schema': (", schema=%r" % _ident(op.schema)) if op.schema else '', } return text diff --git a/docs/build/unreleased/drop_repr.rst b/docs/build/unreleased/drop_repr.rst new file mode 100644 index 00000000..3f3c5999 --- /dev/null +++ b/docs/build/unreleased/drop_repr.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, autogenerate + + The "op.drop_constraint()" directive will now render using ``repr()`` for + the schema name, in the same way that "schema" renders for all the other op + directives. Pull request courtesy Denis Kataev. diff --git a/tests/test_autogen_render.py b/tests/test_autogen_render.py index c02157b8..b122e378 100644 --- a/tests/test_autogen_render.py +++ b/tests/test_autogen_render.py @@ -364,6 +364,24 @@ class AutogenRenderTest(TestBase): "schema='CamelSchema', type_='unique')" ) + def test_drop_unique_constraint_schema_reprobj(self): + """ + autogenerate.render._drop_constraint using schema + """ + class SomeObj(str): + def __repr__(self): + return "foo.camel_schema" + + op_obj = ops.DropConstraintOp( + "uq_test_code", "test", type_="unique", + schema=SomeObj("CamelSchema") + ) + eq_ignore_whitespace( + autogenerate.render_op_text(self.autogen_context, op_obj), + "op.drop_constraint('uq_test_code', 'test', " + "schema=foo.camel_schema, type_='unique')" + ) + def test_add_fk_constraint(self): m = MetaData() Table('a', m, Column('id', Integer, primary_key=True))