diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-09-19 09:40:40 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-09-19 18:39:18 -0400 |
| commit | c9af2ebf5e5d288aea3a3a26bdf950e08ac4f927 (patch) | |
| tree | 5d16ad838a53613ca04b4984db14658e84f187f0 /test/sql | |
| parent | f0bcd57f9ed76ba8d871448d821a85089f490b6c (diff) | |
| download | sqlalchemy-c9af2ebf5e5d288aea3a3a26bdf950e08ac4f927.tar.gz | |
break out text() from TextualSelect for col matching
Fixed issue where mixing "*" with additional explicitly-named column
expressions within the columns clause of a :func:`_sql.select` construct
would cause result-column targeting to sometimes consider the label name or
other non-repeated names to be an ambiguous target.
Fixes: #8536
Change-Id: I3c845eaf571033e54c9208762344f67f4351ac3a
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_resultset.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 5df5c8a73..42cf31bf5 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -1158,6 +1158,50 @@ class CursorResultTest(fixtures.TablesTest): set([True]), ) + @testing.combinations( + (("name_label", "*"), False), + (("*", "name_label"), False), + (("user_id", "name_label", "user_name"), False), + (("user_id", "name_label", "*", "user_name"), True), + argnames="cols,other_cols_are_ambiguous", + ) + @testing.requires.select_star_mixed + def test_label_against_star( + self, connection, cols, other_cols_are_ambiguous + ): + """test #8536""" + users = self.tables.users + + connection.execute(users.insert(), dict(user_id=1, user_name="john")) + + stmt = select( + *[ + text("*") + if colname == "*" + else users.c.user_name.label("name_label") + if colname == "name_label" + else users.c[colname] + for colname in cols + ] + ) + + row = connection.execute(stmt).first() + + eq_(row._mapping["name_label"], "john") + + if other_cols_are_ambiguous: + with expect_raises_message( + exc.InvalidRequestError, "Ambiguous column name" + ): + row._mapping["user_id"] + with expect_raises_message( + exc.InvalidRequestError, "Ambiguous column name" + ): + row._mapping["user_name"] + else: + eq_(row._mapping["user_id"], 1) + eq_(row._mapping["user_name"], "john") + def test_loose_matching_one(self, connection): users = self.tables.users addresses = self.tables.addresses |
