]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
The :meth:`.ColumnOperators.in_` operator will now coerce
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 2 Feb 2013 21:17:58 +0000 (16:17 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 2 Feb 2013 21:17:58 +0000 (16:17 -0500)
values of ``None`` to :func:`.null`.
[ticket:2496]

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

index e6cc169b1def98bb2cf33cdeb99313264ebdc97f..259c59243e1d12309a137af6e4a8c798f8852c62 100644 (file)
@@ -6,6 +6,13 @@
 .. changelog::
     :version: 0.8.0
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 2496
+
+      The :meth:`.ColumnOperators.in_` operator will now coerce
+      values of ``None`` to :func:`.null`.
+
     .. change::
         :tags: feature, sql
         :tickets: 2657
index de728f77b7f1dda28e0a98588043ff02f2078543..90837f4ab3eb50355f7cd4ab4305c8693b9f8756 100644 (file)
@@ -2084,6 +2084,8 @@ class _DefaultColumnComparator(operators.ColumnOperators):
                     raise exc.InvalidRequestError('in() function accept'
                             's either a list of non-selectable values, '
                             'or a selectable: %r' % o)
+            elif o is None:
+                o = null()
             else:
                 o = expr._bind_param(op, o)
             args.append(o)
index 210f8c7489018e8db470ddd553fc58599d103a16..52ba77310ba6615da60912c5d4964919b43cf567 100644 (file)
@@ -171,6 +171,10 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
                 select([t]).where(t.c.foo.in_(['x', 'y', 'z'])),
                 "SELECT sometable.foo FROM sometable WHERE sometable.foo "
                 "IN ('x', 'y', 'z')",
+            ),
+            (
+                    t.c.foo.in_([None]),
+                    "sometable.foo IN (NULL)"
             )
         ]:
             self.assert_compile(expr, compile, dialect=mxodbc_dialect)
index 45f4978ed128beb4d260f75786d6c9462c2d4e8b..7215ae565221844d45f53e037b2beb6d7edabe53 100644 (file)
@@ -736,6 +736,12 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
             {'param_1': 10}
         )
 
+    def test_in_28(self):
+        self.assert_compile(
+            self.table1.c.myid.in_([None]),
+            "mytable.myid IN (NULL)"
+        )
+
 class MathOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL):
     __dialect__ = 'default'