summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/context.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-04-22 10:45:01 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-04-22 15:09:27 -0400
commit17072f8b04c6a3a989673e85ace163620f9130cd (patch)
tree559661c76a4ad19ce957b4c9248108169cf94b9b /lib/sqlalchemy/orm/context.py
parent72f43a8b49803cd4d4befe91635f6691965f34fb (diff)
downloadsqlalchemy-17072f8b04c6a3a989673e85ace163620f9130cd.tar.gz
omit text from selected_columns; clear memoizations
Fixed regression where usage of the :func:`_sql.text` construct inside the columns clause of a :class:`_sql.Select` construct, which is better handled by using a :func:`_sql.literal_column` construct, would nonetheless prevent constructs like :func:`_sql.union` from working correctly. Other use cases, such as constructing subuqeries, continue to work the same as in prior versions where the :func:`_sql.text` construct is silently omitted from the collection of exported columns. Also repairs similar use within the ORM. This adds a new internal method _all_selected_columns. The existing "selected_columns" collection can't store a TextClause and this never worked, so they are omitted. The TextClause is also not "exported", i.e. available for SELECT from a subquery, as was already the case in 1.3, so the "exported_columns" and "exported_columns_iterator" accessors are where we now omit TextClause. Fixed regression involving legacy methods such as :meth:`_sql.Select.append_column` where internal assertions would fail. Fixes: #6343 Fixes: #6261 Change-Id: I7c2e5b9ae5d94131c77599a020f4310dcf812bcf
Diffstat (limited to 'lib/sqlalchemy/orm/context.py')
-rw-r--r--lib/sqlalchemy/orm/context.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py
index b0b8faee7..6cdad9f41 100644
--- a/lib/sqlalchemy/orm/context.py
+++ b/lib/sqlalchemy/orm/context.py
@@ -789,6 +789,14 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
@classmethod
def exported_columns_iterator(cls, statement):
+ return (
+ elem
+ for elem in cls.all_selected_columns(statement)
+ if not elem._is_text_clause
+ )
+
+ @classmethod
+ def all_selected_columns(cls, statement):
for element in statement._raw_columns:
if (
element.is_selectable
@@ -2614,7 +2622,10 @@ class _RawColumnEntity(_ColumnEntity):
self.expr = column
self.raw_column_index = raw_column_index
self.translate_raw_column = raw_column_index is not None
- self._label_name = compile_state._label_convention(column)
+ if column._is_text_clause:
+ self._label_name = None
+ else:
+ self._label_name = compile_state._label_convention(column)
if parent_bundle:
parent_bundle._entities.append(self)