summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/strategies.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-09-23 15:17:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-09-23 17:18:37 -0400
commit4d6d402d73cb64877b21bb3917bda8cf1a23f296 (patch)
tree97b87b050fd9bfd2a0b99b6269589129b8c6357f /lib/sqlalchemy/orm/strategies.py
parentbbd90a987eea70c28dd1e2ee7007722b16ec9f74 (diff)
downloadsqlalchemy-4d6d402d73cb64877b21bb3917bda8cf1a23f296.tar.gz
remove should_nest behavior for contains_eager()
Fixed regression for 1.4 in :func:`_orm.contains_eager` where the "wrap in subquery" logic of :func:`_orm.joinedload` would be inadvertently triggered for use of the :func:`_orm.contains_eager` function with similar statements (e.g. those that use ``distinct()``, ``limit()`` or ``offset()``). This is not appropriate for :func:`_orm.contains_eager` which has always had the contract that the user-defined SQL statement is unmodified with the exception of adding the appropriate columns. Also includes an adjustment to the assertion in Label._make_proxy() which was there to prevent a fixed label name from being anonymized; if the label is already anonymous, the change should proceed. This logic was being hit before the contains_eager behavior was adjusted. With the adjustment, this code is not used. Fixes: #8569 Change-Id: I161e65041c0162fd2b83cbef40f57a50fcfaf0fd (cherry picked from commit 57b400f07951f0ae8651ca38338ec5be1d222c7e)
Diffstat (limited to 'lib/sqlalchemy/orm/strategies.py')
-rw-r--r--lib/sqlalchemy/orm/strategies.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 944c114a6..a014b2f41 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -1965,6 +1965,9 @@ class JoinedLoader(AbstractRelationshipLoader):
)
if user_defined_adapter is not False:
+
+ # setup an adapter but dont create any JOIN, assume it's already
+ # in the query
(
clauses,
adapter,
@@ -1976,6 +1979,11 @@ class JoinedLoader(AbstractRelationshipLoader):
adapter,
user_defined_adapter,
)
+
+ # don't do "wrap" for multi-row, we want to wrap
+ # limited/distinct SELECT,
+ # because we want to put the JOIN on the outside.
+
else:
# if not via query option, check for
# a cycle
@@ -1986,6 +1994,7 @@ class JoinedLoader(AbstractRelationshipLoader):
elif path.contains_mapper(self.mapper):
return
+ # add the JOIN and create an adapter
(
clauses,
adapter,
@@ -2002,6 +2011,10 @@ class JoinedLoader(AbstractRelationshipLoader):
chained_from_outerjoin,
)
+ # for multi-row, we want to wrap limited/distinct SELECT,
+ # because we want to put the JOIN on the outside.
+ compile_state.eager_adding_joins = True
+
with_poly_entity = path.get(
compile_state.attributes, "path_with_polymorphic", None
)