summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/elements.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-05-10 22:52:49 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-05-10 23:42:41 -0400
commitb146a0c64144639bf02bafda239238e3a8f5c84d (patch)
treec9c21a160e14aa177a40f11cf436bc0b2e160659 /lib/sqlalchemy/sql/elements.py
parent39c2815fb25052c181f98ca52a57fd7449d7090c (diff)
downloadsqlalchemy-b146a0c64144639bf02bafda239238e3a8f5c84d.tar.gz
set bindparam.expanding in coercion again
Adjusted the logic added as part of :ticket:`6397` in 1.4.12 so that internal mutation of the :class:`.BindParameter` object occurs within the clause construction phase as it did before, rather than in the compilation phase. In the latter case, the mutation still produced side effects against the incoming construct and additionally could potentially interfere with other internal mutation routines. In order to solve the issue of the correct operator being present on the BindParameter.expand_op, we necessarily have to expand the BinaryExpression._negate() routine to flip the operator on the BindParameter also. Fixes: #6460 Change-Id: I1e53a9aeee4de4fc11af51d7593431532731561b
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r--lib/sqlalchemy/sql/elements.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 416a4e82e..cdb1dbca8 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -256,6 +256,15 @@ class ClauseElement(
return c
+ def _negate_in_binary(self, negated_op, original_op):
+ """a hook to allow the right side of a binary expression to respond
+ to a negation of the binary expression.
+
+ Used for the special case of expanding bind parameter with IN.
+
+ """
+ return self
+
def _with_binary_element_type(self, type_):
"""in the context of binary expression, convert the type of this
object to the one given.
@@ -1510,6 +1519,14 @@ class BindParameter(roles.InElementRole, ColumnElement):
literal_execute=True,
)
+ def _negate_in_binary(self, negated_op, original_op):
+ if self.expand_op is original_op:
+ bind = self._clone()
+ bind.expand_op = negated_op
+ return bind
+ else:
+ return self
+
def _with_binary_element_type(self, type_):
c = ClauseElement._clone(self)
c.type = type_
@@ -3729,7 +3746,7 @@ class BinaryExpression(ColumnElement):
if self.negate is not None:
return BinaryExpression(
self.left,
- self.right,
+ self.right._negate_in_binary(self.negate, self.operator),
self.negate,
negate=self.operator,
type_=self.type,