]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Copy whereclause / using in ExcludeConstraint
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Jan 2017 17:10:16 +0000 (12:10 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Jan 2017 17:10:16 +0000 (12:10 -0500)
Fixed bug in Postgresql :class:`.ExcludeConstraint` where the
"whereclause" and "using" parameters would not be copied during an
operation like :meth:`.Table.tometadata`.

Change-Id: I2f704981d4d4862f9c82a50272006fab8becebb6
Fixes: #3900
doc/build/changelog/changelog_11.rst
lib/sqlalchemy/dialects/postgresql/ext.py
test/dialect/postgresql/test_compiler.py

index 33eca2eca6f643581f429a741dd1d556a27871e6..906f570ff87bd0070551b2614cf5858852103e52 100644 (file)
 .. changelog::
     :version: 1.1.6
 
+    .. change:: 3900
+        :tags: bug, postgresql
+        :tickets: 3900
+
+        Fixed bug in Postgresql :class:`.ExcludeConstraint` where the
+        "whereclause" and "using" parameters would not be copied during an
+        operation like :meth:`.Table.tometadata`.
+
     .. change:: 3898
         :tags: bug, mssql
         :tickets: 3898
index e3ac79f30051fdd84bcd24252f83099084ebf549..55eded90a19b1f403fc1b6386a407b539ae80791 100644 (file)
@@ -199,7 +199,9 @@ static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
         c = self.__class__(*elements,
                            name=self.name,
                            deferrable=self.deferrable,
-                           initially=self.initially)
+                           initially=self.initially,
+                           where=self.where,
+                           using=self.using)
         c.dispatch._update(self.dispatch)
         return c
 
index 99706bad847ed7e4ea512b3e94b679f96af87a56..16064185557066d8895c7db78bcfe6a54d2a3275 100644 (file)
@@ -555,6 +555,30 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
                             'ALTER TABLE testtbl ADD EXCLUDE USING gist '
                             '(room WITH =)')
 
+    def test_exclude_constraint_copy_where_using(self):
+        m = MetaData()
+        tbl = Table('testtbl', m,
+                    Column('room', Integer, primary_key=True),
+                    )
+        cons = ExcludeConstraint(
+            (tbl.c.room, '='), where=tbl.c.room > 5, using='foobar')
+        tbl.append_constraint(cons)
+        self.assert_compile(
+            schema.AddConstraint(cons),
+            "ALTER TABLE testtbl ADD EXCLUDE USING foobar "
+            "(room WITH =) WHERE (testtbl.room > 5)"
+        )
+
+        m2 = MetaData()
+        tbl2 = tbl.tometadata(m2)
+        self.assert_compile(
+            schema.CreateTable(tbl2),
+            "CREATE TABLE testtbl (room SERIAL NOT NULL, "
+            "PRIMARY KEY (room), "
+            "EXCLUDE USING foobar "
+            "(room WITH =) WHERE (testtbl.room > 5))"
+        )
+
     def test_exclude_constraint_text(self):
         m = MetaData()
         cons = ExcludeConstraint((text('room::TEXT'), '='))