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_9_0b1~143 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=34ef21909bd6ed3574e37c345ca9e10761f087bd;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 451127fbb9..909cda4762 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/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 03e2ba5156..d9788aed22 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -6,6 +6,13 @@ .. changelog:: :version: 0.9.0 + .. 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. Also in 0.8.3. + .. change:: :tags: orm, feature, orm diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index b00a7399ae..121583cf83 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2132,7 +2132,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'