diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-27 20:44:46 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-27 22:18:01 -0400 |
commit | 7fdaac7b2910b5612420378519b9f60d4649daff (patch) | |
tree | 7d3f72c3c88aaaa8d54affd1f3ac3f9bd55cc00f /lib/sqlalchemy/orm/context.py | |
parent | 2af1b107fce34b15898e6f534097ad34cfd7d503 (diff) | |
download | sqlalchemy-7fdaac7b2910b5612420378519b9f60d4649daff.tar.gz |
don't mutate the statement in ORM compile
Fixed issue where using a :class:`_sql.Select` as a subquery in an ORM
context would modify the :class:`_sql.Select` in place to disable
eagerloads on that object, which would then cause that same
:class:`_sql.Select` to not eagerload if it were then re-used in a
top-level execution context.
Fixes: #6378
Change-Id: I945048c4c148587b933fb65a3fc83a05d05c052d
Diffstat (limited to 'lib/sqlalchemy/orm/context.py')
-rw-r--r-- | lib/sqlalchemy/orm/context.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/context.py b/lib/sqlalchemy/orm/context.py index 6cdad9f41..f62115fda 100644 --- a/lib/sqlalchemy/orm/context.py +++ b/lib/sqlalchemy/orm/context.py @@ -517,15 +517,6 @@ class ORMSelectCompileState(ORMCompileState, SelectState): for_statement ) = select_statement._compile_options._for_statement - if not for_statement and not toplevel: - # for subqueries, turn off eagerloads. - # if "for_statement" mode is set, Query.subquery() - # would have set this flag to False already if that's what's - # desired - select_statement._compile_options += { - "_enable_eagerloads": False, - } - # generally if we are from Query or directly from a select() self.use_legacy_query_style = ( select_statement._compile_options._use_legacy_query_style @@ -546,6 +537,15 @@ class ORMSelectCompileState(ORMCompileState, SelectState): self.compile_options = select_statement._compile_options + if not for_statement and not toplevel: + # for subqueries, turn off eagerloads. + # if "for_statement" mode is set, Query.subquery() + # would have set this flag to False already if that's what's + # desired + self.compile_options += { + "_enable_eagerloads": False, + } + # determine label style. we can make different decisions here. # at the moment, trying to see if we can always use DISAMBIGUATE_ONLY # rather than LABEL_STYLE_NONE, and if we can use disambiguate style |