From: Mike Bayer Date: Wed, 23 Jun 2021 12:50:48 +0000 (-0400) Subject: consider "*" col as textual ordered X-Git-Tag: rel_1_4_20~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdd041ea60628b2f4fd7f7da562aa19bdb15c206;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git consider "*" col as textual ordered Fixed old issue where a :func:`_sql.select()` made against the token "*", which then yielded exactly one column, would fail to correctly organize the ``cursor.description`` column name into the keys of the result object. Fixes: #6665 Change-Id: Ie8c00f62998972ad4a19a750d2642d00fde006f6 --- diff --git a/doc/build/changelog/unreleased_14/6665.rst b/doc/build/changelog/unreleased_14/6665.rst new file mode 100644 index 0000000000..f7b53d5d44 --- /dev/null +++ b/doc/build/changelog/unreleased_14/6665.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, engine + :tickets: 6665 + + Fixed old issue where a :func:`_sql.select()` made against the token "*", + which then yielded exactly one column, would fail to correctly organize the + ``cursor.description`` column name into the keys of the result object. + + diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index f47ea8f33a..8ae56fd544 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2805,7 +2805,7 @@ class SQLCompiler(Compiled): return " AS " + alias_name_text def _add_to_result_map(self, keyname, name, objects, type_): - if keyname is None: + if keyname is None or keyname == "*": self._ordered_columns = False self._textual_ordered_columns = True if type_._is_tuple_type: diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 44422257af..892cfee535 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -421,6 +421,28 @@ class CursorResultTest(fixtures.TablesTest): eq_(r._mapping["user_name"], "jack") eq_(r._mapping[users.c.user_name], "jack") + @testing.combinations( + (select(literal_column("1").label("col1")), ("col1",)), + ( + select( + literal_column("1").label("col1"), + literal_column("2").label("col2"), + ), + ("col1", "col2"), + ), + argnames="sql,cols", + ) + def test_compiled_star_doesnt_interfere_w_description( + self, connection, sql, cols + ): + """test #6665""" + + row = connection.execute( + select("*").select_from(sql.subquery()) + ).first() + eq_(row._fields, cols) + eq_(row._mapping["col1"], 1) + def test_row_getitem_string(self, connection): users = self.tables.users