From 2d5fa22c7d53ff8109d47ba5ae4fe3b9849ddd09 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 30 Dec 2019 13:08:17 -0500 Subject: Include GROUP BY in _should_nest_selectable criteria Fixed bug where usage of joined eager loading would not properly wrap the query inside of a subquery when :meth:`.Query.group_by` were used against the query. When any kind of result-limiting approach is used, such as DISTINCT, LIMIT, OFFSET, joined eager loading embeds the row-limited query inside of a subquery so that the collection results are not impacted. For some reason, the presence of GROUP BY was never included in this criterion, even though it has a similar effect as using DISTINCT. Additionally, the bug would prevent using GROUP BY at all for a joined eager load query for most database platforms which forbid non-aggregated, non-grouped columns from being in the query, as the additional columns for the joined eager load would not be accepted by the database. Fixes: #5065 Change-Id: I9a2ed8196f83297ec38012138d1a5acdf9e88155 --- lib/sqlalchemy/orm/query.py | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 80d544068..22e24be84 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -3479,6 +3479,7 @@ class Query(Generative): kwargs.get("limit") is not None or kwargs.get("offset") is not None or kwargs.get("distinct", False) + or kwargs.get("group_by", False) ) def exists(self): -- cgit v1.2.1