From 462ccd9ff18d2e428b20ec3f596391a275472140 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 15 Aug 2018 17:11:14 -0400 Subject: Add concept of "implicit boolean", treat as native Fixed issue that is closely related to :ticket:`3639` where an expression rendered in a boolean context on a non-native boolean backend would be compared to 1/0 even though it is already an implcitly boolean expression, when :meth:`.ColumnElement.self_group` were used. While this does not affect the user-friendly backends (MySQL, SQLite) it was not handled by Oracle (and possibly SQL Server). Whether or not the expression is implicitly boolean on any database is now determined up front as an additional check to not generate the integer comparison within the compliation of the statement. Fixes: #4320 Change-Id: Iae0a65e5c01bd576e64733c3651e1e1a1a1b240c --- lib/sqlalchemy/sql/compiler.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 5fbc7d87f..e45db428a 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1019,13 +1019,15 @@ class SQLCompiler(Compiled): "Unary expression has no operator or modifier") def visit_istrue_unary_operator(self, element, operator, **kw): - if self.dialect.supports_native_boolean: + if element._is_implicitly_boolean or \ + self.dialect.supports_native_boolean: return self.process(element.element, **kw) else: return "%s = 1" % self.process(element.element, **kw) def visit_isfalse_unary_operator(self, element, operator, **kw): - if self.dialect.supports_native_boolean: + if element._is_implicitly_boolean or \ + self.dialect.supports_native_boolean: return "NOT %s" % self.process(element.element, **kw) else: return "%s = 0" % self.process(element.element, **kw) -- cgit v1.2.1