]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix postgresql exclude contraint to check when= against None rather than __bool__...
authoraisch <me+bosch@aitmp.com>
Mon, 23 Nov 2015 18:22:50 +0000 (10:22 -0800)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Nov 2015 18:01:33 +0000 (13:01 -0500)
(cherry picked from commit 0921a6abbc8246c57f447af7a6ac240778127fae)

lib/sqlalchemy/dialects/postgresql/constraints.py
test/dialect/postgresql/test_compiler.py

index 4cfc050de5e5f75f45df207ee3407da4621aa513..2a6dc1d932d091268f644414f0b07f326c3c6d5e 100644 (file)
@@ -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):
index 9fa5c98043ed16badbd962cfe6147514a110f12f..427ffc2adf9cfd88992f9053b78d4c995eae352e 100644 (file)
@@ -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 '