]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Use repr for drop_constraint schema
authorDenis Kataev <bteamko@gmail.com>
Wed, 11 Apr 2018 14:27:34 +0000 (10:27 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Apr 2018 14:30:43 +0000 (10:30 -0400)
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

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

index 0ba12dac5c1d83177317bb1c9156316c1852a40e..0459d7a64a7548f0fb8adf4f2e6479923b830efd 100644 (file)
@@ -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 (file)
index 0000000..3f3c599
--- /dev/null
@@ -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.
index c02157b865627a62a80a36583e36d20dceb19235..b122e3785dab63a27db7079e881c3fe8808c100b 100644 (file)
@@ -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))