diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-04-29 19:53:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-04-29 19:53:02 +0000 |
| commit | dc5485b7ecdbe1cbed34fcb8d748fbe975aee140 (patch) | |
| tree | 7f0456f166b53fecf881c6e214b69dc7db4944e3 /test/sql | |
| parent | 28493bf4bc35a4802b57b02a8b389cec7b6dcbb6 (diff) | |
| parent | aba308868544b21bafa0b3435701ddc908654b0a (diff) | |
| download | sqlalchemy-dc5485b7ecdbe1cbed34fcb8d748fbe975aee140.tar.gz | |
Merge "Use non-subquery form for empty IN"
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_lambdas.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/sql/test_lambdas.py b/test/sql/test_lambdas.py index 24a83c9ee..897c60f00 100644 --- a/test/sql/test_lambdas.py +++ b/test/sql/test_lambdas.py @@ -116,6 +116,46 @@ class LambdaElementTest( result = go() eq_(result.all(), [(2,)]) + def test_in_expressions(self, user_address_fixture, connection): + """test #6397. we initially were going to use two different + forms for "empty in" vs. regular "in", but instead we have an + improved substitution for "empty in". regardless, as there's more + going on with these, make sure lambdas work with them including + caching. + + """ + users, _ = user_address_fixture + data = [ + {"id": 1, "name": "u1"}, + {"id": 2, "name": "u2"}, + {"id": 3, "name": "u3"}, + ] + connection.execute(users.insert(), data) + + def go(val): + stmt = lambdas.lambda_stmt(lambda: select(users.c.id)) + stmt += lambda s: s.where(users.c.name.in_(val)) + stmt += lambda s: s.order_by(users.c.id) + return connection.execute(stmt) + + for case in [ + [], + ["u1", "u2"], + ["u3"], + [], + ["u1", "u2"], + ]: + with testing.assertsql.assert_engine(testing.db) as asserter_: + result = go(case) + asserter_.assert_( + CompiledSQL( + "SELECT users.id FROM users WHERE users.name " + "IN ([POSTCOMPILE_val_1]) ORDER BY users.id", + params={"val_1": case}, + ) + ) + eq_(result.all(), [(e["id"],) for e in data if e["name"] in case]) + def test_stale_checker_embedded(self): def go(x): |
