From: Mike Bayer Date: Sat, 22 Sep 2012 20:45:02 +0000 (-0400) Subject: - aaand actually get is/isnot to be usable with None/NULL X-Git-Tag: rel_0_8_0b1~143 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6c50ffcf44b8e363a5d3590955be1f62fd5e780d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - aaand actually get is/isnot to be usable with None/NULL --- diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 50f8061a64..f00926e4d6 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1952,10 +1952,10 @@ class _DefaultColumnComparator(operators.ColumnOperators): **kwargs ): if obj is None or isinstance(obj, Null): - if op == operators.eq: + if op in (operators.eq, operators.is_): return BinaryExpression(expr, null(), operators.is_, negate=operators.isnot) - elif op == operators.ne: + elif op in (operators.ne, operators.isnot): return BinaryExpression(expr, null(), operators.isnot, negate=operators.is_) else: @@ -3156,6 +3156,9 @@ class Null(ColumnElement): def __init__(self): self.type = sqltypes.NULLTYPE + def compare(self, other): + return isinstance(other, Null) + class False_(ColumnElement): """Represent the ``false`` keyword in a SQL statement. diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index a6c99be43d..951309d195 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -20,9 +20,8 @@ class DefaultColumnComparatorTest(fixtures.TestBase): compare_to(left) ) - def _do_operate_test(self, operator): + def _do_operate_test(self, operator, right=column('right')): left = column('left') - right = column('right') assert left.comparator.operate(operator, right).compare( BinaryExpression(left, right, operator) @@ -41,6 +40,12 @@ class DefaultColumnComparatorTest(fixtures.TestBase): def test_plus(self): self._do_operate_test(operators.add) + def test_is_null(self): + self._do_operate_test(operators.is_, None) + + def test_isnot_null(self): + self._do_operate_test(operators.isnot, None) + def test_is(self): self._do_operate_test(operators.is_)