]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
consider "*" col as textual ordered
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 23 Jun 2021 12:50:48 +0000 (08:50 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 23 Jun 2021 13:49:11 +0000 (09:49 -0400)
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

doc/build/changelog/unreleased_14/6665.rst [new file with mode: 0644]
lib/sqlalchemy/sql/compiler.py
test/sql/test_resultset.py

diff --git a/doc/build/changelog/unreleased_14/6665.rst b/doc/build/changelog/unreleased_14/6665.rst
new file mode 100644 (file)
index 0000000..f7b53d5
--- /dev/null
@@ -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.
+
+
index f47ea8f33a43caded613e4883608f932686e11ec..8ae56fd5440418a824708053cc5ebc24a9481fd4 100644 (file)
@@ -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:
index 44422257af71d6b0a75442ae3b54cd06e0302f29..892cfee535b88db3f7b950b55072fbf103c38774 100644 (file)
@@ -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