diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-07 11:12:31 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-11 14:20:10 -0400 |
| commit | aceefb508ccd0911f52ff0e50324b3fefeaa3f16 (patch) | |
| tree | e57124d3ea8b0e2cd7fe1d3ad22170fa956bcafb /test/sql | |
| parent | 5c16367ee78fa1a41d6b715152dcc58f45323d2e (diff) | |
| download | sqlalchemy-aceefb508ccd0911f52ff0e50324b3fefeaa3f16.tar.gz | |
Allow duplicate columns in from clauses and selectables
The :func:`.select` construct and related constructs now allow for
duplication of column labels and columns themselves in the columns clause,
mirroring exactly how column expressions were passed in. This allows
the tuples returned by an executed result to match what was SELECTed
for in the first place, which is how the ORM :class:`.Query` works, so
this establishes better cross-compatibility between the two constructs.
Additionally, it allows column-positioning-sensitive structures such as
UNIONs (i.e. :class:`.CompoundSelect`) to be more intuitively constructed
in those cases where a particular column might appear in more than one
place. To support this change, the :class:`.ColumnCollection` has been
revised to support duplicate columns as well as to allow integer index
access.
Fixes: #4753
Change-Id: Ie09a8116f05c367995c1e43623c51e07971d3bf0
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_compiler.py | 51 | ||||
| -rw-r--r-- | test/sql/test_cte.py | 6 | ||||
| -rw-r--r-- | test/sql/test_join_rewriting.py | 156 | ||||
| -rw-r--r-- | test/sql/test_metadata.py | 3 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 85 |
5 files changed, 228 insertions, 73 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index ea1a9bd75..cd462fb77 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -531,8 +531,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_dupe_columns(self): - """test that deduping is performed against clause - element identity, not rendered result.""" + """as of 1.4, there's no deduping.""" self.assert_compile( select([column("a"), column("a"), column("a")]), @@ -542,13 +541,15 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): c = column("a") self.assert_compile( - select([c, c, c]), "SELECT a", dialect=default.DefaultDialect() + select([c, c, c]), + "SELECT a, a, a", + dialect=default.DefaultDialect(), ) a, b = column("a"), column("b") self.assert_compile( select([a, b, b, b, a, a]), - "SELECT a, b", + "SELECT a, b, b, b, a, a", dialect=default.DefaultDialect(), ) @@ -560,7 +561,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( select([a, b, c, a, b, c]), - "SELECT a, b, c", + "SELECT a, b, c, a, b, c", dialect=default.DefaultDialect(), ) @@ -584,6 +585,18 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): s = s.compile(dialect=default.DefaultDialect(paramstyle="qmark")) eq_(s.positiontup, ["a", "b", "c"]) + def test_dupe_columns_use_labels(self): + """as of 1.4, there's no deduping. + + however the labels will still uniqify themselves... + """ + + t = table("t", column("a"), column("b")) + self.assert_compile( + select([t.c.a, t.c.a, t.c.b]).apply_labels(), + "SELECT t.a AS t_a, t.a AS t_a_1, t.b AS t_b FROM t", + ) + def test_nested_label_targeting(self): """test nested anonymous label generation. @@ -2050,6 +2063,22 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): {"param_1": 10}, ) + def test_dupe_cols_hey_we_can_union(self): + """test the original inspiration for [ticket:4753].""" + + s1 = select([table1, table1.c.myid]).where(table1.c.myid == 5) + s2 = select([table1, table2.c.otherid]).where( + table1.c.myid == table2.c.otherid + ) + self.assert_compile( + union(s1, s2).order_by(s1.selected_columns.myid), + "SELECT mytable.myid, mytable.name, mytable.description, " + "mytable.myid FROM mytable WHERE mytable.myid = :myid_1 " + "UNION SELECT mytable.myid, mytable.name, mytable.description, " + "myothertable.otherid FROM mytable, myothertable " + "WHERE mytable.myid = myothertable.otherid ORDER BY myid", + ) + def test_compound_grouping(self): s = select([column("foo"), column("bar")]).select_from(text("bat")) @@ -4511,7 +4540,8 @@ class ResultMapTest(fixtures.TestBase): t = table("a", column("x"), column("y"), column("z")) l1, l2, l3 = t.c.z.label("a"), t.c.x.label("b"), t.c.x.label("c") - orig = [t.c.x, t.c.y, l1, l2, l3] + + orig = [t.c.x, t.c.y, l1, t.c.y, l2, t.c.x, l3] # create the statement with some duplicate columns. right now # the behavior is that these redundant columns are deduped. @@ -4520,11 +4550,11 @@ class ResultMapTest(fixtures.TestBase): # so the statement has 7 inner columns... eq_(len(list(stmt.inner_columns)), 7) - # but only exposes 5 of them, the other two are dupes of x and y - eq_(len(stmt.subquery().c), 5) + # 7 are exposed as of 1.4, no more deduping + eq_(len(stmt.subquery().c), 7) - # and when it generates a SELECT it will also render only 5 - eq_(len(stmt._columns_plus_names), 5) + # will render 7 as well + eq_(len(stmt._columns_plus_names), 7) wrapped = stmt._generate() wrapped = wrapped.column( @@ -4543,4 +4573,5 @@ class ResultMapTest(fixtures.TestBase): proxied = [obj[0] for (k, n, obj, type_) in compiled._result_columns] for orig_obj, proxied_obj in zip(orig, proxied): + is_(orig_obj, proxied_obj) diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py index ac46e7d5d..26f367e9f 100644 --- a/test/sql/test_cte.py +++ b/test/sql/test_cte.py @@ -815,6 +815,7 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): "regional_sales_1 " "AS anon_2, regional_sales_1 " 'WHERE orders."order" = :3) SELECT regional_sales_2.anon_1, ' + 'regional_sales_2."order", regional_sales_2."order", ' 'regional_sales_2."order" FROM regional_sales_2', checkpositional=("x", "y", "z"), dialect=dialect, @@ -862,8 +863,9 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): 'regional_sales_1."order" AS "order" ' "FROM orders, regional_sales_1 AS anon_2, regional_sales_1 " "WHERE orders.\"order\" = 'z') " - 'SELECT regional_sales_2.anon_1, regional_sales_2."order" ' - "FROM regional_sales_2", + "SELECT regional_sales_2.anon_1, " + 'regional_sales_2."order", regional_sales_2."order", ' + 'regional_sales_2."order" FROM regional_sales_2', checkpositional=(), dialect=dialect, literal_binds=True, diff --git a/test/sql/test_join_rewriting.py b/test/sql/test_join_rewriting.py index a966af4e4..573455e7d 100644 --- a/test/sql/test_join_rewriting.py +++ b/test/sql/test_join_rewriting.py @@ -7,6 +7,7 @@ from sqlalchemy import Column from sqlalchemy import exists from sqlalchemy import ForeignKey from sqlalchemy import Integer +from sqlalchemy import literal_column from sqlalchemy import MetaData from sqlalchemy import select from sqlalchemy import Table @@ -14,10 +15,11 @@ from sqlalchemy import testing from sqlalchemy import union from sqlalchemy import util from sqlalchemy.engine import default +from sqlalchemy.sql import elements from sqlalchemy.testing import AssertsCompiledSQL +from sqlalchemy.testing import eq_ from sqlalchemy.testing import fixtures - m = MetaData() @@ -92,11 +94,15 @@ class _JoinRewriteTestBase(AssertsCompiledSQL): compiled = s.compile(dialect=self.__dialect__) - # column name should be in result map, as we never render - # .key in SQL - for key, col in zip([c.name for c in s.subquery().c], s.inner_columns): - key = key % compiled.anon_map - assert col in compiled._create_result_map()[key][1] + for rec, (name, col) in zip( + compiled._result_columns, s._columns_plus_names + ): + assert col in set(rec[2]) + if ( + not isinstance(name, elements._anonymous_label) + and name is not None + ): + eq_(rec[1], name) _a_bkeyselect_bkey = "" @@ -128,6 +134,48 @@ class _JoinRewriteTestBase(AssertsCompiledSQL): self._test(s, self._a_bc) + def test_a_bc_preserve_dupes(self): + j1 = b.join(c) + j2 = a.join(j1) + + s = ( + select( + [a.c.id, b.c.id, b.c.a_id, c, b.c.a_id, c.c.b_id], + use_labels=True, + ) + .select_from(j2) + .where(b.c.id == 2) + .where(c.c.id == 3) + .order_by(a.c.id, b.c.id, c.c.id) + ) + + self._test(s, self._a_bc_wdupes) + + def test_a_bc_preserve_dupes_anon_map(self): + j1 = b.join(c) + j2 = a.join(j1) + + s = ( + select( + [a.c.id, b.c.id, b.c.a_id, c, b.c.a_id, c.c.b_id], + use_labels=True, + ) + .select_from(j2) + .where(b.c.id == 2) + .where(c.c.id == 3) + ) + + # the anon_map needs to be preserved after the transform + # as the labels are going to be referred to outside of the query + subq = s.subquery() + s2 = ( + select([literal_column("1")]) + .select_from(subq) + .where(subq.c[5] == subq.c[6]) + ) + + self._test(s2, self._a_bc_wdupes_anon_map) + def test_a_bkeyassoc(self): j1 = b_key.join(a_to_b_key) j2 = a.join(j1) @@ -311,6 +359,35 @@ class JoinRewriteTest(_JoinRewriteTestBase, fixtures.TestBase): "ORDER BY a.id, anon_1.b_id, anon_1.c_id" ) + _a_bc_wdupes = ( + "SELECT a.id AS a_id, anon_1.b_id AS b_id, anon_1.b_a_id AS b_a_id, " + "anon_1.c_id AS c_id, anon_1.c_b_id AS c_b_id, " + "anon_1.b_a_id AS b_a_id_1, anon_1.c_b_id AS c_b_id_1 " + "FROM a JOIN " + "(SELECT b.id AS b_id, b.a_id AS b_a_id, c.id AS c_id, " + "c.b_id AS c_b_id " + "FROM b JOIN c ON b.id = c.b_id) AS anon_1 ON a.id = anon_1.b_a_id " + "WHERE anon_1.b_id = :id_1 AND anon_1.c_id = :id_2 " + "ORDER BY a.id, anon_1.b_id, anon_1.c_id" + ) + + _a_bc_wdupes_anon_map = ( + "SELECT 1 FROM (SELECT a.id AS a_id, b.id AS b_id, b.a_id AS b_a_id, " + "c.id AS c_id, c.b_id AS c_b_id, b.a_id AS b_a_id_1, " + "c.b_id AS c_b_id_1 " + "FROM a JOIN (b JOIN c ON b.id = c.b_id) ON a.id = b.a_id " + "WHERE b.id = :id_1 AND c.id = :id_2) AS anon_1 " + "WHERE anon_1.b_a_id_1 = anon_1.c_b_id_1" + ) + + _a_bc_wdupes_anon_map = ( + "SELECT 1 FROM (SELECT a.id AS a_id, b.id AS b_id, b.a_id AS b_a_id, " + "c.id AS c_id, c.b_id AS c_b_id, b.a_id AS b_a_id_1, " + "c.b_id AS c_b_id_1 FROM a JOIN (b JOIN c ON b.id = c.b_id) " + "ON a.id = b.a_id WHERE b.id = :id_1 AND c.id = :id_2) AS anon_1 " + "WHERE anon_1.b_a_id_1 = anon_1.c_b_id_1" + ) + _a_bc_comma_a1_selbc = ( "SELECT a.id AS a_id, a_1.id AS a_1_id, anon_1.b_id AS b_id, " "anon_1.b_a_id AS b_a_id, anon_1.c_id AS c_id, " @@ -346,15 +423,14 @@ class JoinRewriteTest(_JoinRewriteTestBase, fixtures.TestBase): ) _a_bkeyselect_bkey = ( - "SELECT a.id AS a_id, anon_2.anon_1_aid AS anon_1_aid, " - "anon_2.anon_1_bid AS anon_1_bid, anon_2.b_key_id AS b_key_id " - "FROM a JOIN (SELECT anon_1.aid AS anon_1_aid, " - "anon_1.bid AS anon_1_bid, " + "SELECT a.id AS a_id, anon_1.b_key_id AS b_key_id " + "FROM a JOIN (SELECT anon_2.aid AS anon_2_aid, " + "anon_2.bid AS anon_2_bid, " "b_key.id AS b_key_id " "FROM (SELECT a_to_b_key.aid AS aid, a_to_b_key.bid AS bid " - "FROM a_to_b_key) AS anon_1 " - "JOIN b_key ON b_key.id = anon_1.bid) AS anon_2 " - "ON a.id = anon_2.anon_1_aid" + "FROM a_to_b_key) AS anon_2 " + "JOIN b_key ON b_key.id = anon_2.bid) AS anon_1 " + "ON a.id = anon_1.anon_2_aid" ) _a_atobalias_balias_c_w_exists = ( @@ -400,8 +476,8 @@ class JoinRewriteTest(_JoinRewriteTestBase, fixtures.TestBase): _b_a_id_double_overlap_annotated = ( "SELECT anon_1.b_id AS anon_1_b_id, anon_1.b_a_id AS anon_1_b_a_id, " - "anon_1.id_1 AS anon_1_id_1 " - "FROM (SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS id_1 " + "anon_1.b_a_id_1 AS anon_1_b_a_id_1 " + "FROM (SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS b_a_id_2 " "FROM b JOIN b_a ON b.id = b_a.id) AS anon_1" ) @@ -433,6 +509,7 @@ class JoinPlainTest(_JoinRewriteTestBase, fixtures.TestBase): "FROM a_to_b_key) AS anon_1 JOIN b_key ON b_key.id = anon_1.bid) " "ON a.id = anon_1.aid" ) + _a__b_dc = ( "SELECT a.id AS a_id, b.id AS b_id, " "b.a_id AS b_a_id, c.id AS c_id, " @@ -455,6 +532,25 @@ class JoinPlainTest(_JoinRewriteTestBase, fixtures.TestBase): "ORDER BY a.id, b.id, c.id" ) + _a_bc_wdupes = ( + "SELECT a.id AS a_id, b.id AS b_id, b.a_id AS b_a_id, c.id AS c_id, " + "c.b_id AS c_b_id, b.a_id AS b_a_id_1, c.b_id AS c_b_id_1 " + "FROM a JOIN " + "(b JOIN c ON b.id = c.b_id) " + "ON a.id = b.a_id " + "WHERE b.id = :id_1 AND c.id = :id_2 " + "ORDER BY a.id, b.id, c.id" + ) + + _a_bc_wdupes_anon_map = ( + "SELECT 1 FROM (SELECT a.id AS a_id, b.id AS b_id, b.a_id AS b_a_id, " + "c.id AS c_id, c.b_id AS c_b_id, b.a_id AS b_a_id_1, " + "c.b_id AS c_b_id_1 " + "FROM a JOIN (b JOIN c ON b.id = c.b_id) ON a.id = b.a_id " + "WHERE b.id = :id_1 AND c.id = :id_2) AS anon_1 " + "WHERE anon_1.b_a_id_1 = anon_1.c_b_id_1" + ) + _a_bc_comma_a1_selbc = ( "SELECT a.id AS a_id, a_1.id AS a_1_id, b.id AS b_id, " "b.a_id AS b_a_id, c.id AS c_id, " @@ -517,8 +613,8 @@ class JoinPlainTest(_JoinRewriteTestBase, fixtures.TestBase): _b_a_id_double_overlap_annotated = ( "SELECT anon_1.b_id AS anon_1_b_id, anon_1.b_a_id AS anon_1_b_a_id, " - "anon_1.id_1 AS anon_1_id_1 FROM " - "(SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS id_1 " + "anon_1.b_a_id_1 AS anon_1_b_a_id_1 FROM " + "(SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS b_a_id_1 " "FROM b JOIN b_a ON b.id = b_a.id) AS anon_1" ) @@ -573,6 +669,24 @@ class JoinNoUseLabelsTest(_JoinRewriteTestBase, fixtures.TestBase): "ORDER BY a.id, b.id, c.id" ) + _a_bc_wdupes = ( + "SELECT a.id, b.id, b.a_id, c.id, c.b_id, b.a_id, c.b_id " + "FROM a JOIN " + "(b JOIN c ON b.id = c.b_id) " + "ON a.id = b.a_id " + "WHERE b.id = :id_1 AND c.id = :id_2 " + "ORDER BY a.id, b.id, c.id" + ) + + _a_bc_wdupes_anon_map = ( + "SELECT 1 FROM (SELECT a.id AS a_id, b.id AS b_id, b.a_id AS b_a_id, " + "c.id AS c_id, c.b_id AS c_b_id, b.a_id AS b_a_id_1, " + "c.b_id AS c_b_id_1 " + "FROM a JOIN (b JOIN c ON b.id = c.b_id) ON a.id = b.a_id " + "WHERE b.id = :id_1 AND c.id = :id_2) AS anon_1 " + "WHERE anon_1.b_a_id_1 = anon_1.c_b_id_1" + ) + _a_bc_comma_a1_selbc = ( "SELECT a.id, a_1.id, b.id, " "b.a_id, c.id, " @@ -626,8 +740,8 @@ class JoinNoUseLabelsTest(_JoinRewriteTestBase, fixtures.TestBase): ) _b_a_id_double_overlap_annotated = ( - "SELECT anon_1.b_id, anon_1.b_a_id, anon_1.id_1 FROM " - "(SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS id_1 " + "SELECT anon_1.b_id, anon_1.b_a_id, anon_1.b_a_id_1 FROM " + "(SELECT b.id AS b_id, b.a_id AS b_a_id, b_a.id AS b_a_id_1 " "FROM b JOIN b_a ON b.id = b_a.id) AS anon_1" ) @@ -650,6 +764,10 @@ class JoinExecTest(_JoinRewriteTestBase, fixtures.TestBase): __backend__ = True _a_bc = ( + _a_bc_wdupes + ) = ( + _a_bc_wdupes_anon_map + ) = ( _a_bc_comma_a1_selbc ) = ( _a__b_dc diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 5081cfbd2..f3fa008c5 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -1518,6 +1518,7 @@ class TableTest(fixtures.TestBase, AssertsCompiledSQL): y = Column("y", Integer) t1 = Table("t", m, Column("x", Integer), y) + # note we are testing immutable column collection here t2 = pickle.loads(pickle.dumps(t1)) z = Column("z", Integer) g = Column("g", Integer) @@ -2530,7 +2531,7 @@ class ConstraintTest(fixtures.TestBase): i = Index("i", t.c.x, _table=t) is_(i.table, t) - eq_(i.columns, [t.c.x]) + eq_(list(i.columns), [t.c.x]) def test_inline_decl_columns(self): m = MetaData() diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 485a0e428..9bcdd0620 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -656,27 +656,23 @@ class SelectableTest( s2 = select([table2.c.col1, table2.c.col2, table2.c.col3]) u1 = union(s1, s2).subquery() - with testing.expect_warnings("Column 'col1'"): - u1.c - assert ( u1.corresponding_column(s1.selected_columns._all_columns[0]) is u1.c._all_columns[0] ) - # due to the duplicate key, "col1" is now the column at the end - # of the list and the first column is not accessible by key - assert u1.c.col1 is u1.c._all_columns[2] + # col1 is taken by the first "col1" in the list + assert u1.c.col1 is u1.c._all_columns[0] # table2.c.col1 is in two positions in this union, so...currently # it is the replaced one at position 2. assert u1.corresponding_column(table2.c.col1) is u1.c._all_columns[2] - # this is table2.c.col1 in both cases, so this is "right" - assert u1.corresponding_column(s2.selected_columns.col1) is u1.c.col1 + # this is table2.c.col1, which in the first selectable is in position 2 + assert u1.corresponding_column(s2.selected_columns.col1) is u1.c[2] # same - assert u1.corresponding_column(s2.subquery().c.col1) is u1.c.col1 + assert u1.corresponding_column(s2.subquery().c.col1) is u1.c[2] # col2 is working OK assert u1.corresponding_column(s1.selected_columns.col2) is u1.c.col2 @@ -691,8 +687,8 @@ class SelectableTest( ) assert u1.corresponding_column(s2.subquery().c.col2) is u1.c.col2 - # col3 is also "correct" , though confusing - assert u1.corresponding_column(s2.selected_columns.col3) is u1.c.col1 + # col3 is also "correct" + assert u1.corresponding_column(s2.selected_columns.col3) is u1.c[2] assert u1.corresponding_column(table1.c.col1) is u1.c._all_columns[0] assert u1.corresponding_column(table1.c.col2) is u1.c._all_columns[1] @@ -705,22 +701,23 @@ class SelectableTest( s2 = select([table2.c.col1, table2.c.col2, table2.c.col3]).limit(1) u1 = union(s1, s2).subquery() - with testing.expect_warnings("Column 'col1'"): - u1.c + assert ( + u1.corresponding_column(s1.selected_columns._all_columns[0]) + is u1.c._all_columns[0] + ) - # due to the duplicate key, "col1" is now the column at the end - # of the list and the first column is not accessible by key - assert u1.c.col1 is u1.c._all_columns[2] + # col1 is taken by the first "col1" in the list + assert u1.c.col1 is u1.c._all_columns[0] # table2.c.col1 is in two positions in this union, so...currently # it is the replaced one at position 2. assert u1.corresponding_column(table2.c.col1) is u1.c._all_columns[2] - # this is table2.c.col1 in both cases, so this is "right" - assert u1.corresponding_column(s2.selected_columns.col1) is u1.c.col1 + # this is table2.c.col1, which in the first selectable is in position 2 + assert u1.corresponding_column(s2.selected_columns.col1) is u1.c[2] # same - assert u1.corresponding_column(s2.subquery().c.col1) is u1.c.col1 + assert u1.corresponding_column(s2.subquery().c.col1) is u1.c[2] # col2 is working OK assert u1.corresponding_column(s1.selected_columns.col2) is u1.c.col2 @@ -735,8 +732,8 @@ class SelectableTest( ) assert u1.corresponding_column(s2.subquery().c.col2) is u1.c.col2 - # col3 is also "correct" , though confusing - assert u1.corresponding_column(s2.selected_columns.col3) is u1.c.col1 + # col3 is also "correct" + assert u1.corresponding_column(s2.selected_columns.col3) is u1.c[2] assert u1.corresponding_column(table1.c.col1) is u1.c._all_columns[0] assert u1.corresponding_column(table1.c.col2) is u1.c._all_columns[1] @@ -2610,13 +2607,6 @@ class ReprTest(fixtures.TestBase): class WithLabelsTest(fixtures.TestBase): - def _assert_labels_warning(self, s): - assert_raises_message( - exc.SAWarning, - r"replaced by Column.*, which has the same key", - lambda: s.subquery().c, - ) - def _assert_result_keys(self, s, keys): compiled = s.compile() eq_(set(compiled._create_result_map()), set(keys)) @@ -2633,7 +2623,6 @@ class WithLabelsTest(fixtures.TestBase): def test_names_overlap_nolabel(self): sel = self._names_overlap() - self._assert_labels_warning(sel) self._assert_result_keys(sel, ["x"]) def test_names_overlap_label(self): @@ -2675,10 +2664,16 @@ class WithLabelsTest(fixtures.TestBase): def test_labels_overlap_label(self): sel = self._labels_overlap().apply_labels() t2 = sel.froms[1] - eq_(list(sel.selected_columns.keys()), ["t_x_id", t2.c.id.anon_label]) - eq_(list(sel.subquery().c.keys()), ["t_x_id", t2.c.id.anon_label]) - self._assert_result_keys(sel, ["t_x_id", "id_1"]) - self._assert_subq_result_keys(sel, ["t_x_id", "id_1"]) + eq_( + list(sel.selected_columns.keys()), + ["t_x_id", t2.c.id._label_anon_label], + ) + eq_( + list(sel.subquery().c.keys()), + ["t_x_id", t2.c.id._label_anon_label], + ) + self._assert_result_keys(sel, ["t_x_id", "t_x_id_1"]) + self._assert_subq_result_keys(sel, ["t_x_id", "t_x_id_1"]) def _labels_overlap_keylabels_dont(self): m = MetaData() @@ -2696,7 +2691,7 @@ class WithLabelsTest(fixtures.TestBase): sel = self._labels_overlap_keylabels_dont().apply_labels() eq_(list(sel.selected_columns.keys()), ["t_a", "t_x_b"]) eq_(list(sel.subquery().c.keys()), ["t_a", "t_x_b"]) - self._assert_result_keys(sel, ["t_x_id", "id_1"]) + self._assert_result_keys(sel, ["t_x_id", "t_x_id_1"]) def _keylabels_overlap_labels_dont(self): m = MetaData() @@ -2713,8 +2708,14 @@ class WithLabelsTest(fixtures.TestBase): def test_keylabels_overlap_labels_dont_label(self): sel = self._keylabels_overlap_labels_dont().apply_labels() t2 = sel.froms[1] - eq_(list(sel.selected_columns.keys()), ["t_x_id", t2.c.id.anon_label]) - eq_(list(sel.subquery().c.keys()), ["t_x_id", t2.c.id.anon_label]) + eq_( + list(sel.selected_columns.keys()), + ["t_x_id", t2.c.id._label_anon_label], + ) + eq_( + list(sel.subquery().c.keys()), + ["t_x_id", t2.c.id._label_anon_label], + ) self._assert_result_keys(sel, ["t_a", "t_x_b"]) self._assert_subq_result_keys(sel, ["t_a", "t_x_b"]) @@ -2734,10 +2735,13 @@ class WithLabelsTest(fixtures.TestBase): def test_keylabels_overlap_labels_overlap_label(self): sel = self._keylabels_overlap_labels_overlap().apply_labels() t2 = sel.froms[1] - eq_(list(sel.selected_columns.keys()), ["t_x_a", t2.c.a.anon_label]) - eq_(list(sel.subquery().c.keys()), ["t_x_a", t2.c.a.anon_label]) - self._assert_result_keys(sel, ["t_x_id", "id_1"]) - self._assert_subq_result_keys(sel, ["t_x_id", "id_1"]) + eq_( + list(sel.selected_columns.keys()), + ["t_x_a", t2.c.a._label_anon_label], + ) + eq_(list(sel.subquery().c.keys()), ["t_x_a", t2.c.a._label_anon_label]) + self._assert_result_keys(sel, ["t_x_id", "t_x_id_1"]) + self._assert_subq_result_keys(sel, ["t_x_id", "t_x_id_1"]) def _keys_overlap_names_dont(self): m = MetaData() @@ -2747,7 +2751,6 @@ class WithLabelsTest(fixtures.TestBase): def test_keys_overlap_names_dont_nolabel(self): sel = self._keys_overlap_names_dont() - self._assert_labels_warning(sel) self._assert_result_keys(sel, ["a", "b"]) def test_keys_overlap_names_dont_label(self): |
