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.
(self, user_address_fixture, connection)
| 149 | eq_(result.all(), [(2,)]) |
| 150 | |
| 151 | def test_in_expressions(self, user_address_fixture, connection): |
| 152 | """test #6397. we initially were going to use two different |
| 153 | forms for "empty in" vs. regular "in", but instead we have an |
| 154 | improved substitution for "empty in". regardless, as there's more |
| 155 | going on with these, make sure lambdas work with them including |
| 156 | caching. |
| 157 | |
| 158 | """ |
| 159 | users, _ = user_address_fixture |
| 160 | data = [ |
| 161 | {"id": 1, "name": "u1"}, |
| 162 | {"id": 2, "name": "u2"}, |
| 163 | {"id": 3, "name": "u3"}, |
| 164 | ] |
| 165 | connection.execute(users.insert(), data) |
| 166 | |
| 167 | def go(val): |
| 168 | stmt = lambdas.lambda_stmt(lambda: select(users.c.id)) |
| 169 | stmt += lambda s: s.where(users.c.name.in_(val)) |
| 170 | stmt += lambda s: s.order_by(users.c.id) |
| 171 | return connection.execute(stmt) |
| 172 | |
| 173 | for case in [ |
| 174 | [], |
| 175 | ["u1", "u2"], |
| 176 | ["u3"], |
| 177 | [], |
| 178 | ["u1", "u2"], |
| 179 | ]: |
| 180 | with testing.assertsql.assert_engine(testing.db) as asserter_: |
| 181 | result = go(case) |
| 182 | asserter_.assert_( |
| 183 | CompiledSQL( |
| 184 | "SELECT users.id FROM users WHERE users.name " |
| 185 | "IN (__[POSTCOMPILE_val_1]) ORDER BY users.id", |
| 186 | params={"val_1": case}, |
| 187 | ) |
| 188 | ) |
| 189 | eq_(result.all(), [(e["id"],) for e in data if e["name"] in case]) |
| 190 | |
| 191 | def test_in_expr_compile(self, user_address_fixture): |
| 192 | users, _ = user_address_fixture |