test issue #6698, regression caused by #6503
(self, legacy, threelevel)
| 341 | @testing.combinations((True,), (False,), argnames="legacy") |
| 342 | @testing.combinations((True,), (False,), argnames="threelevel") |
| 343 | def test_join_and_union_with_entities(self, legacy, threelevel): |
| 344 | """test issue #6698, regression caused by #6503""" |
| 345 | |
| 346 | User, Address, Dingaling = self.classes("User", "Address", "Dingaling") |
| 347 | |
| 348 | if legacy: |
| 349 | sess = fixture_session() |
| 350 | stmt = sess.query(User).join(Address).with_entities(Address.id) |
| 351 | else: |
| 352 | stmt = select(User).join(Address).with_only_columns(Address.id) |
| 353 | |
| 354 | stmt = stmt.set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) |
| 355 | |
| 356 | if threelevel: |
| 357 | if legacy: |
| 358 | stmt = stmt.join(Address.dingaling).with_entities(Dingaling.id) |
| 359 | |
| 360 | to_union = sess.query(Dingaling.id) |
| 361 | else: |
| 362 | stmt = stmt.join(Address.dingaling).with_only_columns( |
| 363 | Dingaling.id |
| 364 | ) |
| 365 | to_union = select(Dingaling.id).set_label_style( |
| 366 | LABEL_STYLE_TABLENAME_PLUS_COL |
| 367 | ) |
| 368 | else: |
| 369 | if legacy: |
| 370 | to_union = sess.query(Address.id) |
| 371 | else: |
| 372 | to_union = select(Address.id).set_label_style( |
| 373 | LABEL_STYLE_TABLENAME_PLUS_COL |
| 374 | ) |
| 375 | |
| 376 | if legacy: |
| 377 | stmt = stmt.union(to_union) |
| 378 | else: |
| 379 | stmt = ( |
| 380 | union(stmt, to_union) |
| 381 | .subquery() |
| 382 | .select() |
| 383 | .set_label_style(LABEL_STYLE_TABLENAME_PLUS_COL) |
| 384 | ) |
| 385 | |
| 386 | if threelevel: |
| 387 | self.assert_compile( |
| 388 | stmt, |
| 389 | "SELECT anon_1.dingalings_id AS anon_1_dingalings_id FROM " |
| 390 | "(SELECT dingalings.id AS dingalings_id " |
| 391 | "FROM users JOIN addresses ON users.id = addresses.user_id " |
| 392 | "JOIN dingalings ON addresses.id = dingalings.address_id " |
| 393 | "UNION " |
| 394 | "SELECT dingalings.id AS dingalings_id FROM dingalings) " |
| 395 | "AS anon_1", |
| 396 | ) |
| 397 | else: |
| 398 | self.assert_compile( |
| 399 | stmt, |
| 400 | "SELECT anon_1.addresses_id AS anon_1_addresses_id FROM " |
nothing calls this directly
no test coverage detected