From: aisch Date: Mon, 23 Nov 2015 18:22:50 +0000 (-0800) Subject: fix postgresql exclude contraint to check when= against None rather than __bool__... X-Git-Tag: rel_1_0_10~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb2b486de5570878b6fe1be75debdffc66a5a287;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix postgresql exclude contraint to check when= against None rather than __bool__ eval (cherry picked from commit 0921a6abbc8246c57f447af7a6ac240778127fae) --- diff --git a/lib/sqlalchemy/dialects/postgresql/constraints.py b/lib/sqlalchemy/dialects/postgresql/constraints.py index 4cfc050de5..2a6dc1d932 100644 --- a/lib/sqlalchemy/dialects/postgresql/constraints.py +++ b/lib/sqlalchemy/dialects/postgresql/constraints.py @@ -84,7 +84,7 @@ static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE ) self.using = kw.get('using', 'gist') where = kw.get('where') - if where: + if where is not None: self.where = expression._literal_as_text(where) def copy(self, **kw): diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 9fa5c98043..427ffc2adf 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -508,6 +508,19 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): '(CAST("Room" AS TEXT) WITH =)' ) + def test_exclude_constraint_when(self): + m = MetaData() + tbl = Table( + 'testtbl', m, + Column('room', String) + ) + cons = ExcludeConstraint(('room', '='), where=tbl.c.room.in_(['12'])) + tbl.append_constraint(cons) + self.assert_compile(schema.AddConstraint(cons), + 'ALTER TABLE testtbl ADD EXCLUDE USING gist ' + '(room WITH =) WHERE (testtbl.room IN (\'12\'))', + dialect=postgresql.dialect()) + def test_substring(self): self.assert_compile(func.substring('abc', 1, 2), 'SUBSTRING(%(substring_1)s FROM %(substring_2)s '