From 433d2ee9f14a028399e848f3552a1a71f223c976 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 27 Apr 2017 10:26:10 -0400 Subject: Enforce boolean result type for all eq_, is_, isnot, comparison Repaired issue where the type of an expression that used :meth:`.ColumnOperators.is_` or similar would not be a "boolean" type, instead the type would be "nulltype", as well as when using custom comparison operators against an untyped expression. This typing can impact how the expression behaves in larger contexts as well as in result-row-handling. Change-Id: Ib810ff686de500d8db26ae35a51005fab29603b6 Fixes: #3873 --- lib/sqlalchemy/sql/default_comparator.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/default_comparator.py') diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py index 4ba53ef75..4485c661b 100644 --- a/lib/sqlalchemy/sql/default_comparator.py +++ b/lib/sqlalchemy/sql/default_comparator.py @@ -50,11 +50,15 @@ def _boolean_compare(expr, op, obj, negate=None, reverse=False, if op in (operators.eq, operators.is_): return BinaryExpression(expr, _const_expr(obj), operators.is_, - negate=operators.isnot) + negate=operators.isnot, + type_=result_type + ) elif op in (operators.ne, operators.isnot): return BinaryExpression(expr, _const_expr(obj), operators.isnot, - negate=operators.is_) + negate=operators.is_, + type_=result_type + ) else: raise exc.ArgumentError( "Only '=', '!=', 'is_()', 'isnot()', " -- cgit v1.2.1