summaryrefslogtreecommitdiff
path: root/test/sql/test_operators.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 /test/sql/test_operators.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 'test/sql/test_operators.py')
-rw-r--r--test/sql/test_operators.py52
1 files changed, 46 insertions, 6 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index f3e5282fd..984379c6b 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -1975,15 +1975,20 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
literal_binds=True,
)
- @testing.combinations(True, False)
- def test_in_empty_tuple(self, is_in):
+ @testing.combinations(True, False, argnames="is_in")
+ @testing.combinations(True, False, argnames="negate")
+ def test_in_empty_tuple(self, is_in, negate):
a, b, c = (
column("a", Integer),
column("b", String),
column("c", LargeBinary),
)
t1 = tuple_(a, b, c)
- expr = t1.in_([]) if is_in else t1.not_in([])
+
+ if negate:
+ expr = ~t1.not_in([]) if is_in else ~t1.in_([])
+ else:
+ expr = t1.in_([]) if is_in else t1.not_in([])
if is_in:
self.assert_compile(
@@ -2010,10 +2015,15 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
dialect="default_enhanced",
)
- @testing.combinations(True, False)
- def test_in_empty_single(self, is_in):
+ @testing.combinations(True, False, argnames="is_in")
+ @testing.combinations(True, False, argnames="negate")
+ def test_in_empty_single(self, is_in, negate):
a = column("a", Integer)
- expr = a.in_([]) if is_in else a.not_in([])
+
+ if negate:
+ expr = ~a.not_in([]) if is_in else ~a.in_([])
+ else:
+ expr = a.in_([]) if is_in else a.not_in([])
if is_in:
self.assert_compile(
@@ -2040,6 +2050,36 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
dialect="default_enhanced",
)
+ def test_in_self_plus_negated(self):
+ a = column("a", Integer)
+
+ expr1 = a.in_([5])
+ expr2 = ~expr1
+
+ stmt = and_(expr1, expr2)
+ self.assert_compile(
+ stmt, "a IN ([POSTCOMPILE_a_1]) AND (a NOT IN ([POSTCOMPILE_a_2]))"
+ )
+ self.assert_compile(
+ stmt, "a IN (5) AND (a NOT IN (5))", literal_binds=True
+ )
+
+ def test_in_self_plus_negated_empty(self):
+ a = column("a", Integer)
+
+ expr1 = a.in_([])
+ expr2 = ~expr1
+
+ stmt = and_(expr1, expr2)
+ self.assert_compile(
+ stmt, "a IN ([POSTCOMPILE_a_1]) AND (a NOT IN ([POSTCOMPILE_a_2]))"
+ )
+ self.assert_compile(
+ stmt,
+ "a IN (NULL) AND (1 != 1) AND (a NOT IN (NULL) OR (1 = 1))",
+ literal_binds=True,
+ )
+
def test_in_set(self):
s = {1, 2, 3}
self.assert_compile(