summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-02-02 16:17:58 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-02-02 16:17:58 -0500
commitcb19f227f31701322f398b5bdd77427dfc81da0d (patch)
tree644fb3803e3948888b61ff5b4af804615c66ee8a
parentda3d817f3624d5f631956e33d92799572f47e52f (diff)
downloadsqlalchemy-cb19f227f31701322f398b5bdd77427dfc81da0d.tar.gz
The :meth:`.ColumnOperators.in_` operator will now coerce
values of ``None`` to :func:`.null`. [ticket:2496]
-rw-r--r--doc/build/changelog/changelog_08.rst7
-rw-r--r--lib/sqlalchemy/sql/expression.py2
-rw-r--r--test/dialect/test_mssql.py4
-rw-r--r--test/sql/test_operators.py6
4 files changed, 19 insertions, 0 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst
index e6cc169b1..259c59243 100644
--- a/doc/build/changelog/changelog_08.rst
+++ b/doc/build/changelog/changelog_08.rst
@@ -7,6 +7,13 @@
: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
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index de728f77b..90837f4ab 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -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)
diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py
index 210f8c748..52ba77310 100644
--- a/test/dialect/test_mssql.py
+++ b/test/dialect/test_mssql.py
@@ -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)
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index 45f4978ed..7215ae565 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -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'