From 28493bf4bc35a4802b57b02a8b389cec7b6dcbb6 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 29 Apr 2021 10:40:00 -0400 Subject: accommodate HasEntityNamespace in context.all_selected_columns Fixed regression in hybrid_property where a hybrid against a SQL function would generate an ``AttributeError`` when attempting to generate an entry for the ``.c`` collection of a subquery in some cases; among other things this would impact its use in cases like that of ``Query.count()``. Fixes: #6401 Change-Id: Icc243c699e9a5c88448076c6427ec389eaa8b8ed --- lib/sqlalchemy/orm/context.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/sqlalchemy/orm/context.py') diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py index 55b61b19e..aeba9ed80 100644 --- a/lib/sqlalchemy/orm/context.py +++ b/lib/sqlalchemy/orm/context.py @@ -802,12 +802,13 @@ class ORMSelectCompileState(ORMCompileState, SelectState): element.is_selectable and "entity_namespace" in element._annotations ): - for elem in _select_iterables( - element._annotations[ - "entity_namespace" - ]._all_column_expressions - ): - yield elem + ens = element._annotations["entity_namespace"] + if not ens.is_mapper and not ens.is_aliased_class: + for elem in _select_iterables([element]): + yield elem + else: + for elem in _select_iterables(ens._all_column_expressions): + yield elem else: for elem in _select_iterables([element]): yield elem -- cgit v1.2.1