From: Mike Bayer Date: Wed, 7 Aug 2013 18:28:45 +0000 (-0500) Subject: - The :meth:`.Operators.notin_` operator added in 0.8 now properly X-Git-Tag: rel_0_8_3~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3302187fea0ffd431b980081e7bc483ea364da2b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. Also in 0.8.3. --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 560cc18943..abe4635ebd 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -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 diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index ce3308ede1..ce7322b9d2 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -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), diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index b3919d0dab..ce91c5b5e3 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -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'