summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/default_comparator.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-10-04 11:21:35 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-10-04 12:04:11 -0400
commit81f99c1b143d33e275afef7472750b5174294e80 (patch)
treee0fd0e97a62a8632f80adfca8989d1052fc06b09 /lib/sqlalchemy/sql/default_comparator.py
parent71e463506217e3acc379a3f459e68a81792a0aac (diff)
downloadsqlalchemy-81f99c1b143d33e275afef7472750b5174294e80.tar.gz
repair any_() / all_() "implicit flip" behavior for None
Fixed an inconsistency in the any_() / all_() functions / methods where the special behavior these functions have of "flipping" the expression such that the "ANY" / "ALL" expression is always on the right side would not function if the comparison were against the None value, that is, "column.any_() == None" should produce the same SQL expression as "null() == column.any_()". Added more docs to clarify this as well, plus mentions that any_() / all_() generally supersede the ARRAY version "any()" / "all()". Fixes: #7140 Change-Id: Ia5d55414ba40eb3fbda3598931fdd24c9b4a4411
Diffstat (limited to 'lib/sqlalchemy/sql/default_comparator.py')
-rw-r--r--lib/sqlalchemy/sql/default_comparator.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py
index 557095d04..036a96e9f 100644
--- a/lib/sqlalchemy/sql/default_comparator.py
+++ b/lib/sqlalchemy/sql/default_comparator.py
@@ -34,6 +34,7 @@ def _boolean_compare(
negate=None,
reverse=False,
_python_is_types=(util.NoneType, bool),
+ _any_all_expr=False,
result_type=None,
**kwargs
):
@@ -42,7 +43,6 @@ def _boolean_compare(
result_type = type_api.BOOLEANTYPE
if isinstance(obj, _python_is_types + (Null, True_, False_)):
-
# allow x ==/!= True/False to be treated as a literal.
# this comes out to "== / != true/false" or "1/0" if those
# constants aren't supported and works on all platforms
@@ -69,8 +69,12 @@ def _boolean_compare(
negate=negate,
modifiers=kwargs,
)
+ elif _any_all_expr:
+ obj = coercions.expect(
+ roles.ConstExprRole, element=obj, operator=op, expr=expr
+ )
else:
- # all other None/True/False uses IS, IS NOT
+ # all other None uses IS, IS NOT
if op in (operators.eq, operators.is_):
return BinaryExpression(
expr,