summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/unreleased_14/6665.rst9
-rw-r--r--lib/sqlalchemy/sql/compiler.py2
-rw-r--r--test/sql/test_resultset.py22
3 files changed, 32 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_14/6665.rst b/doc/build/changelog/unreleased_14/6665.rst
new file mode 100644
index 000000000..f7b53d5d4
--- /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 f47ea8f33..8ae56fd54 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 44422257a..892cfee53 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