From: Mike Bayer Date: Mon, 30 Jan 2017 17:10:16 +0000 (-0500) Subject: Copy whereclause / using in ExcludeConstraint X-Git-Tag: rel_1_1_6~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c578a710f14568856dad6a1c0bad1269b4108c4;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Copy whereclause / using in ExcludeConstraint 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 --- diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 33eca2eca6..906f570ff8 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,14 @@ .. 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 diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py index e3ac79f300..55eded90a1 100644 --- a/lib/sqlalchemy/dialects/postgresql/ext.py +++ b/lib/sqlalchemy/dialects/postgresql/ext.py @@ -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 diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 99706bad84..1606418555 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -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'), '='))