]> 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)
committeraisch <me+bosch@aitmp.com>
Mon, 23 Nov 2015 18:22:50 +0000 (10:22 -0800)
lib/sqlalchemy/dialects/postgresql/ext.py
test/dialect/postgresql/test_compiler.py

index 9b2e3fd73390e05bf30b0f73202097248c05c14c..1a443c2d799eaee8135484eede8cba41f6bace67 100644 (file)
@@ -142,7 +142,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 78217bd8255c2abb45e4791b32b47516f516f3d5..13acf8c86756da9c0a5a5b50c1ae7b949adad509 100644 (file)
@@ -510,6 +510,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 '