test #6678 in this case we want to see that the unions include the deferred columns so that if we undefer on the outside we can get the column. #6661 allows this.
(self, deferred_fixture)
| 4250 | eq_(stmt.count(), 3) |
| 4251 | |
| 4252 | def test_nested_union_undeferred(self, deferred_fixture): |
| 4253 | """test #6678 |
| 4254 | |
| 4255 | in this case we want to see that the unions include the deferred |
| 4256 | columns so that if we undefer on the outside we can get the |
| 4257 | column. #6661 allows this. |
| 4258 | |
| 4259 | """ |
| 4260 | User = deferred_fixture |
| 4261 | |
| 4262 | s = fixture_session() |
| 4263 | |
| 4264 | s1 = s.query(User).filter(User.id == 7) |
| 4265 | s2 = s.query(User).filter(User.id == 8) |
| 4266 | |
| 4267 | s3 = s.query(User).filter(User.id == 9) |
| 4268 | |
| 4269 | stmt = ( |
| 4270 | s1.union(s2) |
| 4271 | .union(s3) |
| 4272 | .options(undefer(User.name)) |
| 4273 | .order_by(User.id) |
| 4274 | ) |
| 4275 | self.assert_compile( |
| 4276 | stmt, |
| 4277 | "SELECT anon_1.anon_2_users_id AS anon_1_anon_2_users_id, " |
| 4278 | "anon_1.anon_2_users_name AS anon_1_anon_2_users_name " |
| 4279 | "FROM (" |
| 4280 | "SELECT anon_2.users_id AS anon_2_users_id, " |
| 4281 | "anon_2.users_name AS anon_2_users_name " |
| 4282 | "FROM " |
| 4283 | "(SELECT users.id AS users_id, users.name AS users_name " |
| 4284 | "FROM users WHERE users.id = :id_1 UNION " |
| 4285 | "SELECT users.id AS users_id, users.name AS users_name " |
| 4286 | "FROM users WHERE users.id = :id_2) AS anon_2 " |
| 4287 | "UNION " |
| 4288 | "SELECT users.id AS users_id, users.name AS users_name FROM users " |
| 4289 | "WHERE users.id = :id_3) AS anon_1 " |
| 4290 | "ORDER BY anon_1.anon_2_users_id", |
| 4291 | ) |
| 4292 | |
| 4293 | recs = stmt.all() |
| 4294 | for rec in recs: |
| 4295 | assert "name" in rec.__dict__ |
| 4296 | eq_( |
| 4297 | recs, |
| 4298 | [ |
| 4299 | User(id=7, name="jack"), |
| 4300 | User(id=8, name="ed"), |
| 4301 | User(id=9, name="fred"), |
| 4302 | ], |
| 4303 | ) |
| 4304 | |
| 4305 | eq_(stmt.count(), 3) |
| 4306 | |
| 4307 | |
| 4308 | class AggregateTest(QueryTest): |
nothing calls this directly
no test coverage detected