From 1d2b49bc991ca866fd71da3ccfbcde5093482512 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 11 Feb 2021 14:05:49 -0500 Subject: Further refine labeling for renamed columns Forked from I22f6cf0f0b3360e55299cdcb2452cead2b2458ea we are attempting to decide the case for columns mapped under a different name. since the .key feature of Column seems to support this fully, see if an annotation can be used to indicate an effective .key for a column. The effective change is that the labeling of column expressions in rows has been improved to retain the original name of the ORM attribute even if used in a subquery. References: #5933 Change-Id: If251f556f7d723f50d349f765f1690d6c679d2ef --- test/sql/test_compiler.py | 3 ++- test/sql/test_selectable.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'test/sql') diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 2a543aa61..140de8622 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -659,8 +659,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "SELECT sum(lala(mytable.myid)) AS bar FROM mytable", ) + def test_use_labels_keyed(self): self.assert_compile( - select(keyed), "SELECT keyed.x, keyed.y" ", keyed.z FROM keyed" + select(keyed), "SELECT keyed.x, keyed.y, keyed.z FROM keyed" ) self.assert_compile( diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index e15c74075..9f0c72247 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -3067,11 +3067,11 @@ class WithLabelsTest(fixtures.TestBase): ) eq_( list(sel.selected_columns.keys()), - ["t_x_id", "t_x_b_1"], + ["t_x_id", "t_x_id_1"], ) eq_( list(sel.subquery().c.keys()), - ["t_x_id", "t_x_b_1"], + ["t_x_id", "t_x_id_1"], ) self._assert_result_keys(sel, ["t_a", "t_x_b"]) self._assert_subq_result_keys(sel, ["t_a", "t_x_b"]) @@ -3095,11 +3095,11 @@ class WithLabelsTest(fixtures.TestBase): ) eq_( list(sel.selected_columns.keys()), - ["t_x_a", "t_x_id_1"], + ["t_x_a", "t_x_a_1"], ) # deduping for different cols but same label - eq_(list(sel.subquery().c.keys()), ["t_x_a", "t_x_id_1"]) + eq_(list(sel.subquery().c.keys()), ["t_x_a", "t_x_a_1"]) # if we turn off deduping entirely # eq_(list(sel.subquery().c.keys()), ["t_x_a", "t_x_a"]) @@ -3115,7 +3115,7 @@ class WithLabelsTest(fixtures.TestBase): def test_keys_overlap_names_dont_nolabel(self): sel = self._keys_overlap_names_dont() - eq_(sel.selected_columns.keys(), ["x", "b_1"]) + eq_(sel.selected_columns.keys(), ["x", "x_1"]) self._assert_result_keys(sel, ["a", "b"]) def test_keys_overlap_names_dont_label(self): -- cgit v1.2.1