summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/loading.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-06-24 22:50:06 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2018-06-26 15:41:00 -0400
commitf243c00dda1484da97e706b7237670cdce6f10b9 (patch)
tree217a8209e012abd07d72dfdf3559a5832c0cd902 /lib/sqlalchemy/orm/loading.py
parent677818707471db670d5c3a83b10ebbc65f871881 (diff)
downloadsqlalchemy-f243c00dda1484da97e706b7237670cdce6f10b9.tar.gz
Ensure BakedQuery is cloned before we add options to it
Fixed bug in new polymorphic selectin loading where the BakedQuery used internally would be mutated by the given loader options, which would both inappropriately mutate the subclass query as well as carry over the effect to subsequent queries. Change-Id: Iaceecb50557f78484d09e55b3029a0483dfe873f Fixes: #4286
Diffstat (limited to 'lib/sqlalchemy/orm/loading.py')
-rw-r--r--lib/sqlalchemy/orm/loading.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index a169845d4..0a6f8023a 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -580,17 +580,17 @@ def _load_subclass_via_in(context, path, entity):
def do_load(context, path, states, load_only, effective_entity):
orig_query = context.query
- q._add_lazyload_options(
+ q2 = q._with_lazyload_options(
(enable_opt, ) + orig_query._with_options + (disable_opt, ),
path.parent, cache_path=path
)
if orig_query._populate_existing:
- q.add_criteria(
+ q2.add_criteria(
lambda q: q.populate_existing()
)
- q(context.session).params(
+ q2(context.session).params(
primary_keys=[
state.key[1][0] if zero_idx else state.key[1]
for state, load_attrs in states