]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Include GROUP BY in _should_nest_selectable criteria
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Dec 2019 18:08:17 +0000 (13:08 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Dec 2019 18:17:59 +0000 (13:17 -0500)
commitbc94b51f53f80d1454fd3f7b4a736d2454187296
tree9cb3d07ef7f4d5d8755eed908f1024a5d87751fc
parent458e9a6e4a4436719e014015fdcb4ec744b53c16
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
(cherry picked from commit 2d5fa22c7d53ff8109d47ba5ae4fe3b9849ddd09)
doc/build/changelog/unreleased_13/5065.rst [new file with mode: 0644]
lib/sqlalchemy/orm/query.py
test/orm/test_eager_relations.py
test/orm/test_subquery_relations.py