]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The :meth:`.Operators.notin_` operator added in 0.8 now properly
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Aug 2013 18:28:45 +0000 (13:28 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Aug 2013 18:29:19 +0000 (13:29 -0500)
produces the negation of the expression "IN" returns
when used against an empty collection.  Also in 0.8.3.

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/sql/expression.py
test/sql/test_operators.py

index 560cc18943f0537f760c0f3ac5e4c0003cdd0072..abe4635ebd123bdf78ea30ae9003b13a877cfd17 100644 (file)
@@ -6,6 +6,13 @@
 .. changelog::
     :version: 0.8.3
 
+    .. change::
+        :tags: bug, sql
+
+        The :meth:`.Operators.notin_` operator added in 0.8 now properly
+        produces the negation of the expression "IN" returns
+        when used against an empty collection.
+
     .. change::
         :tags: mysql, bug
         :tickets: 2791
index ce3308ede14fd4d7609593b28e102fd899f3f970..ce7322b9d2024bcdd07269df73ffb2dc2c044d2f 100644 (file)
@@ -2134,7 +2134,10 @@ class _DefaultColumnComparator(operators.ColumnOperators):
                       'contradiction, which nonetheless can be '
                       'expensive to evaluate.  Consider alternative '
                       'strategies for improved performance.' % expr)
-            return expr != expr
+            if op is operators.in_op:
+                return expr != expr
+            else:
+                return expr == expr
 
         return self._boolean_compare(expr, op,
                               ClauseList(*args).self_group(against=op),
index b3919d0dab089fff7e85b7422b55722f2910be0c..ce91c5b5e35759777fc8dae874e36f6102647768 100644 (file)
@@ -768,6 +768,17 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
             "mytable.myid IN (NULL)"
         )
 
+    @testing.emits_warning('.*empty sequence.*')
+    def test_in_29(self):
+        self.assert_compile(self.table1.c.myid.notin_([]),
+        "mytable.myid = mytable.myid")
+
+    @testing.emits_warning('.*empty sequence.*')
+    def test_in_30(self):
+        self.assert_compile(~self.table1.c.myid.in_([]),
+        "mytable.myid = mytable.myid")
+
+
 class MathOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL):
     __dialect__ = 'default'