summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm')
-rw-r--r--lib/sqlalchemy/orm/query.py2
-rw-r--r--lib/sqlalchemy/orm/session.py2
-rw-r--r--lib/sqlalchemy/orm/strategies.py13
3 files changed, 10 insertions, 7 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index d7a2cb409..334283bb9 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -1296,7 +1296,6 @@ class Query(
self._set_select_from([fromclause], set_entity_from)
self._compile_options += {
"_enable_single_crit": False,
- "_statement": None,
}
# this enables clause adaptation for non-ORM
@@ -2620,7 +2619,6 @@ class Query(
roles.SelectStatementRole, statement, apply_propagate_attrs=self
)
self._statement = statement
- self._compile_options += {"_statement": statement}
def first(self):
"""Return the first result of this ``Query`` or
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index f6943cc5f..7b5fa2c73 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -275,7 +275,7 @@ class ORMExecuteState(util.MemoizedSlots):
if not self.is_select:
return None
opts = self.statement._compile_options
- if isinstance(opts, context.ORMCompileState.default_compile_options):
+ if opts.isinstance(context.ORMCompileState.default_compile_options):
return opts
else:
return None
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 7f7bab682..98c57149d 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -939,9 +939,14 @@ class LazyLoader(AbstractRelationshipLoader, util.MemoizedSlots):
)
stmt += lambda stmt: stmt.options(*opts)
- stmt += lambda stmt: stmt._update_compile_options(
- {"_current_path": effective_path}
- )
+ else:
+ # this path is used if there are not already any options
+ # in the query, but an event may want to add them
+ effective_path = state.mapper._path_registry[self.parent_property]
+
+ stmt += lambda stmt: stmt._update_compile_options(
+ {"_current_path": effective_path}
+ )
if use_get:
if self._raise_on_sql:
@@ -2732,6 +2737,7 @@ class SelectInLoader(PostLoader, util.MemoizedSlots):
orm_util.Bundle("pk", *pk_cols), effective_entity
)
.apply_labels()
+ ._set_compile_options(ORMCompileState.default_compile_options)
._set_propagate_attrs(
{
"compile_state_plugin": "orm",
@@ -2769,7 +2775,6 @@ class SelectInLoader(PostLoader, util.MemoizedSlots):
q = q.add_criteria(
lambda q: q.filter(in_expr.in_(sql.bindparam("primary_keys")))
)
-
# a test which exercises what these comments talk about is
# test_selectin_relations.py -> test_twolevel_selectin_w_polymorphic
#